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

Grig Gheorghiu grig.gheorghiu at gmail.com
Mon Feb 6 17:11:22 EST 2006


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