Custom Formatting The Output Of subprocess.Popen

Scott David Daniels Scott.Daniels at Acm.Org
Fri Nov 21 13:50:38 EST 2008


thedsadude at gmail.com wrote:
>   Hello,
> 
>   I'm launching a script as follows:
> <code>
> p = subprocess.Popen(['./p.py', 'aa'])
> 
> p.wait()
> </code>
> 
>   If p.py writes to sys.stdout, then it is shown on the console....
You seem to be missing the fact that ./py is run in a different process.
The "sys.stdout" that p.py uses is different from that in the program 
calling Popen.  In fact, it could be using a different Python.  The
situation is really similar to
     p = subprocess.Popen([<basic program>, 'aa'])
in that you have no way to "muck with the guts" of the subprocess, you
can only post-process its output.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list