Re: [Tutor] Run a cmd program

2005-08-09 Thread Kent Johnson
oliver wrote:
> On 8/9/05, Øyvind <[EMAIL PROTECTED]> wrote:
> 
>>Thanks a lot. However, it didn't work. I got an error stating something
>>along: "Is not recognized as an internal or external command, executable
>>program or .. file" (I don't know how to translate the word . to
>>english).
> 
> 
> That looks like a windows error not a python problem.  Python cannot
> find the path to the uptime executable.  You need to either fully
> qualify the uptime command ( C:\path\to\uptime ) or somehow set the
> path in the python environment.

The commands module is not supported on Windows. It's kind of strange, because 
the module is present, but it doesn't work.

 >>> import commands
 >>> commands.getoutput('java')
"'{' is not recognized as an internal or external command,\noperable program or 
batch file."

Note the '{' - this is the unrecognized command. From the docs for command:
 cmd is actually run as { cmd ; } 2>&1

which shows where the { comes from...

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Run a cmd program

2005-08-09 Thread oliver
On 8/9/05, Øyvind <[EMAIL PROTECTED]> wrote:
> Thanks a lot. However, it didn't work. I got an error stating something
> along: "Is not recognized as an internal or external command, executable
> program or .. file" (I don't know how to translate the word . to
> english).

That looks like a windows error not a python problem.  Python cannot
find the path to the uptime executable.  You need to either fully
qualify the uptime command ( C:\path\to\uptime ) or somehow set the
path in the python environment.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Run a cmd program

2005-08-09 Thread Kent Johnson
Øyvind wrote:
> Hello.
> 
> I need to run a program
> (http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp)
> thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
> /d:04/01/2005" in the command prompt. Is it possible to run a already
> compiled exe file in Python and thereafter get the result out? What
> module/command should I look for to run another program? Googling have
> only given me results about how to run Python..

Try the subprocess module, something like
results = subprocess.Popen('uptime AUTO-SRV-001 /s /d:04/01/2005', 
stdout=subprocess.PIPE).communicate()[0]

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Run a cmd program

2005-08-09 Thread Øyvind
Thanks a lot. However, it didn't work. I got an error stating something
along: "Is not recognized as an internal or external command, executable
program or .. file" (I don't know how to translate the word . to
english).

But, when I looked in the manual about the commands module, I found this:
"Availability: Unix." That might explain. However, in the manual I also
found two other commands to try. 'Execl' which made PythonWin 2.3.5 crash
regardless how I used it, and os.popen. The latter worked perfectly.

Have a great day



 import commands
 commands.getoutput("uptime AUTO-SRV-001 /s /d:04/01/2005")
>
> that should do it
>
> On 8/9/05, Øyvind <[EMAIL PROTECTED]> wrote:
>>
>> Hello.
>>
>> I need to run a program
>> (
>> http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp
>> )
>> thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
>> /d:04/01/2005" in the command prompt. Is it possible to run a already
>> compiled exe file in Python and thereafter get the result out? What
>> module/command should I look for to run another program? Googling have
>> only given me results about how to run Python..
>>
>> Thanks in advance.
>>
>> --
>> This email has been scanned for viruses & spam by Decna as -
>> www.decna.no
>> Denne e-posten er sjekket for virus & spam av Decna as -
>> www.decna.no
>>
>> ___
>> Tutor maillist - Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> --
> This email has been scanned for viruses & spam by Decna as - www.decna.no
> Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no
>
>


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Run a cmd program

2005-08-09 Thread Adam Bark
>>> import commands
>>> commands.getoutput("uptime AUTO-SRV-001 /s /d:04/01/2005")

that should do itOn 8/9/05, Øyvind <[EMAIL PROTECTED]> wrote:
Hello.I need to run a program(http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp)thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
/d:04/01/2005" in the command prompt. Is it possible to run a alreadycompiled exe file in Python and thereafter get the result out? Whatmodule/command should I look for to run another program? Googling have
only given me results about how to run Python..Thanks in advance.--This email has been scanned for viruses & spam by Decna as - www.decna.noDenne e-posten er sjekket for virus & spam av Decna as - 
www.decna.no___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Run a cmd program

2005-08-09 Thread Øyvind
Hello.

I need to run a program
(http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp)
thru Python. It is normally run such as "uptime AUTO-SRV-001 /s
/d:04/01/2005" in the command prompt. Is it possible to run a already
compiled exe file in Python and thereafter get the result out? What
module/command should I look for to run another program? Googling have
only given me results about how to run Python..

Thanks in advance.

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor