yet another os.popen quesion

M

Matthew K Jensen

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
 
D

David Bolen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,677
Latest member
MoisesKoeh

Latest Threads

Top