Popen confusion.

David Bolen db3l at fitlinxx.com
Wed May 22 21:45:49 EDT 2002


Chris Liechti <cliechti at gmx.net> writes:

> olczyk at interaccess.com (Thaddeus L. Olczyk) wrote in 
> news:3cec0da5.14728828 at nntp.interaccess.com:
> 
> > I need to spawn a process in such a way that I have access to three
> > pipes ( the usual suspects ) and am able to retrieve the return
> > status.
> > The python documentation is very confusing about this.
> > Can anyone help?
> > 
> 
> http://python.org/doc/current/lib/os-newstreams.html says:
> """
> popen3(cmd[, mode[, bufsize]])
> Executes cmd as a sub-process. Returns the file objects (child_stdin, 
> child_stdout, child_stderr).
> """
> 
> i think the return value of child_stdout.close() is the exit code.

At least under Windows, it's the last file object (whichever one) that
you close of the three that returns the exit code, since until you
have them all closed, that link to the child process might create a
deadlock trying to get the exit code as the process might not exit.

> however you can also use the popen2 module which has additional 
> functionality:
> http://python.org/doc/current/lib/module-popen2.html and
> http://python.org/doc/current/lib/popen3-objects.html

It may be fine for the OP, but note that these are Unix specific.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list