yet another os.popen quesion
db3l at fitlinxx.com
Thu Sep 16 21:32:58 CEST 2004
matt.torment at gmail.com (Matthew K Jensen) writes:
> I've been trying to find a way to detect when a command run by
> os.popen (or similar) has completed (in Windows, btw). I found such a
> function (i don't remember the exact name and library), but the said
> function was only availible for UNIX, for which I am not currently
> making programs for (but soon plan to). Any ideas?
If you stick with popen (not sure what "similar" is), one approach, if
you don't mind blocking, is just to close your end of the pipe. Under
windows, the result of the close (or in the case of the popen#
functions, the last handle close) will return the result of the child
process, so if the child process hasn't yet terminated, it will block
until the child process does terminate.
Note that if the child process is generating output, you'll probably
want to drain the output (in which case the read will let you know
when the child has exited and closed its end of the pipe) or else
there's some risk the child could block if its output buffers fill,
and never exit yourself, which would be a deadlock condition.
More information about the Python-list