Redirect DOS command output
trentm at ActiveState.com
Thu Feb 10 11:57:20 CET 2000
You want to look as os.popen(). This will give you a handle on the stdout
from the command that you run. If you want access to thye other std file
handles (stderr, stdin), then you will want to look at popen2() and
popen3(). The latter two functions have not been made fully portable yet in
Python 1.5.2 so if you are on Windows then you need to use
win32pipe.popen2() and win32pipe.popen3(). On UNIX they are in the os module
I think (or maybe the posix module, not sure).
In the simple case I usually do something like the following:
for line in os.popen('some command').readlines():
# do some stuff with 'line'...
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of
> daryl_stultz at my-deja.com
> Sent: Thursday, February 10, 2000 5:08 PM
> To: python-list at python.org
> Subject: Redirect DOS command output
> Hey, I'm using os.system() to execute a DOS command (on an NT machine).
> I would like to capture (and parse) the output from the command. I'm
> familiar with sys.stout but I'm not sure how to do this.
> Thanks for the help.
> Sent via Deja.com http://www.deja.com/
> Before you buy.
More information about the Python-list