get output of cmd-line command under MS windows

C

calmar

Hi all,

unfotunately, 'commands.getstatusoutput(command)' does not work under
windows.

Would there be any alternative?

os.system also just provides the exit number I think.

thanks a lot,
and cheers
marco


--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
 
B

Bernard Lebel

You should give a go to os.popen( <system command here> ). Article
6.1.2 and 6.1.3 in the Python Library doc.

I recently wrote a program that would create a pipe using the popen()
method, and would enter a while loop. At each iteration, it would read
one line of the pipe output, and the loop would break when it gets an
empty line (indicating the running application is not running in this
case).

Example:

import os

oPipe = os.popen( "run C:/program files/my app/executable.exe" )

while 1:
sLine = oPipe.read()
print sLine
if sLine == '':
print 'No more line from pipe, exit.'
break



Cheers
Bernard
 
C

Cameron Laird

You should give a go to os.popen( <system command here> ). Article
6.1.2 and 6.1.3 in the Python Library doc.

I recently wrote a program that would create a pipe using the popen()
method, and would enter a while loop. At each iteration, it would read
one line of the pipe output, and the loop would break when it gets an
empty line (indicating the running application is not running in this
case).

Example:

import os

oPipe = os.popen( "run C:/program files/my app/executable.exe" )

while 1:
sLine = oPipe.read()
print sLine
if sLine == '':
print 'No more line from pipe, exit.'
break
.
.
.
If I understand you correctly, this presentation depends on
executable.exe
not emitting any blank lines. Some legitimate command-line
executables *do* have occasion to put out blank lines, though
....
 
C

calmar

Hi Bernhard and all,
oPipe = os.popen( "run C:/program files/my app/executable.exe" )

while 1:
sLine = oPipe.read()
print sLine
if sLine == '':
print 'No more line from pipe, exit.'
break

I see. I saw also os.popen("....").read() or so.

Anyway, not sure if that would also catch stderr?

But doesn't matter. It seems, imagemagick (binaries) won't provide
proper error-codes, but at least when it prints something, something was
not ok probably.

I will check the resulting file, to see if everything went ok, and try
to catch the output like you mentioned.

thanks a lot
marco

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
 
C

calmar

Hi Bernhard,
You should give a go to os.popen( <system command here> ). Article
6.1.2 and 6.1.3 in the Python Library doc.

that was good, but on python2.4

subprocess is GREAT! e.g.:

pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\
stderr=subprocess.PIPE, shell=False)
message = pipe.stdout.read()
error = pipe.stderr.read()

thanks all,
calmar

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top