get output of cmd-line command under MS windows

Bernard Lebel 3dbernard at gmail.com
Wed Feb 8 10:19:28 EST 2006


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


On 2/8/06, calmar <mac at calmar.ws> wrote:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list