Getting both PID and output from a command

Donn Cave donn at u.washington.edu
Fri Mar 19 17:08:31 EST 2004


In article <3cc4824d.0403190259.1e06a578 at posting.google.com>,
 hugh at brokenpipefilms.com (Hugh Macdonald) 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)

You're close there.  You're creating a class instance
that has the pid, but os.popen3 hides it from you.
See popen3.py in the library for details.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list