how do I know when popen() finishes?

David Bolen db3l at fitlinxx.com
Fri Oct 13 18:57:16 EDT 2000


"Mark Hadfield" <m.hadfield at niwa.cri.nz> writes:

> No, it does work on Windows in version 2.0 (I have been using popen & popen3
> recently on 2.0b2, NT4).

Right - up until 2.0, os.popen in a windows environment was only
reliable under Windows NT when you had a parent console (limitation of
the C library).  You could, however, use the win32popen* functions
from the windows extensions on all Windows platforms, but would not
get exit codes from the child processes.

> I have found exit codes (returned as the value of the close method on the
> pipe) to be somewhat unpredictable, but otherwise no problem.

Exit codes should hopefully be predictable for all popen* functions in
Python 2.0 under all Windows environments.  For simple popen() calls
you'll get back whatever the OS supplies.  The only wrinkle with
higher order functions (e.g., popen2 and up) is that you will only get
an exit code when you close the _last_ handle returned from the
original function.  So for example, when you get back all of stdin,
stdout, and stderr to a child when using os.popen3, you have to close
all of them to get an exit code, and the code will be returned from
the close() call on whichever is done last.

This is to avoid deadlocking while waiting for the child to exit and
generate a return code if you haven't closed all handles to the pipe
to that child.

--
-- 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