How does os.popen works ?

Rene Pijlman reageer.in at de.nieuwsgroep
Sat Feb 8 12:00:15 EST 2003


Rouk:
>Hello, i have a problem with os.popen function.
>
>It seems that the command that is launched must be finished before one 
>can read from the pipe which was opened.
>
>I made a script called chld.py that writes several lines on stdout with a 
>pause of one second between them.
>
>Following code wait until all lines have been written.
>>>> a = os.popen("./chld.py", "r", 0)
>>>> a.readline()

Pipes are typically buffered. See the description of the bufsiz
paramtere in section 6.1.2 of the Python Library Reference, and
section 6.8.2. "Flow Control Issues".

With a pipe you shoud expect to receive data only when the other
process has written "enough" data to the pipe. This may take a
while and may indeed happen only when the other process
terminates.

Perhaps you should consider other models for interprocess
communication, such as sockets. For advice from this group you
would have to tell us a little more about your application and
requirements.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl




More information about the Python-list mailing list