Best way to capture output of another command-line program in Win32?

Peter A. Schott paschott at no.yahoo.spamm.com
Mon Feb 6 19:30:15 EST 2006


Thanks, I'll give this a try when I get a chance and will post back if we have
any issues.

-Pete

"Grig Gheorghiu" <grig.gheorghiu at gmail.com> wrote:

> subprocess gets my vote too.
> 
> You can do something like:
> 
> from subprocess import call, Popen, PIPE, STDOUT
> 
> def run_cmd(cmd):
> ....arglist = cmd.split()
> ....p = Popen(arglist, stdout=PIPE, stderr=STDOUT)
> ....output = p.communicate()[0]
> ....return (p.returncode, output)
> 
> rc, output = run_cmd("python setup.py test")
> if rc:
> ....print "Command failed"
> ....sys.exit(rc)
> 
> Grig



More information about the Python-list mailing list