Getting both PID and output from a command

Robin Munn rmunn at pobox.com
Sat Mar 20 09:06:55 EST 2004


Hugh Macdonald <hugh at brokenpipefilms.com> wrote:
> I'm calling a command from within a python script and I need to be
> able to both catch the output (stdout and stderr) from it and also
> have the PID (so that I can kill it)
>
> I can do one or other of these, but I can't find any way to do them
> both at the same time.
>
> So far, I've got the following options:
>
>
> To get the output from the command:
>
>>>> fdin, fdout, fderr = os.popen3(command)

To get stdout and stderr as separate pipes and also have the child's
PID, you want to use the Popen3 class from the popen2 module. See:

    http://www.python.org/doc/current/lib/module-popen2.html
    http://www.python.org/doc/current/lib/popen3-objects.html

for details.

-- 
Robin Munn
rmunn at pobox.com



More information about the Python-list mailing list