Entry
How can I run another application (non Python) from within a Python script and
capture its output?
Does os.popen() work from pythonw?
Jun 4th, 2003 03:56
Xcrash, Nathan Wallace, Jesper Hertel, Niels Diepeveen
os.popen(command_line) returns a pipe from wich you can read the
standard output from the command given by command_line.
That is, for example,
a = os.popen("dir").read()
runs the command "dir" and puts the entire output from the command in
the variable a.
Another function os.popen2() also returns standard error output from the
command, but this does not work in Windows, unfortunately.
Be careful, os.popen only works in a console session, not from pythonw.
This is a problem in the C library.
Also a handy function from the commands module would suffice..
import commands
x = commands.getoutput('ls')