popen4 doesn't block?

Jp Calderone exarkun at intarweb.us
Fri Jan 24 19:49:28 EST 2003


On Fri, Jan 24, 2003 at 11:47:41PM +0000, Terry Hancock wrote:
> Hi,
> I've noticed that "os.popen4" (on Linux) does not block. I'm seeing side 
> effects of the process continuing after the call returns, and that's not 
> what I want. I need to wait until the sub-process is complete before 
> continuing (I think os.system does this, but then I can't get to the input 
> and output streams). How can I acheive that?
> 

    o, i = os.popen4(...)
    output = o.read()

  The call to o.read() will not return until the program's stdout has
closed.  This is almost always the same time as the program is exiting, but
it might be sooner.  You could consider a combination of os.pipe(),
os.fork(), os.execl(), and os.wait() if you need to handle programs that
close their stdout/stderr before they actually exit.

  Jp


-- 
There are 10 kinds of people: those who understand binary and those who do
not.
-- 
 up 40 days, 3:49, 4 users, load average: 0.33, 0.44, 0.53
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030124/695e4585/attachment.sig>


More information about the Python-list mailing list