By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,258 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,258 IT Pros & Developers. It's quick & easy.

yet another os.popen quesion

P: n/a
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?

-Matt K. Jensen
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ma**********@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.

-- David
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.