Unbuffer stdout?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Wed Mar 26 06:48:59 CET 2003

Francis Avila wrote:
>>>>sys.stdout.write( os.popen("yes", 'r', 0).read() )
> hangs forever (with some disk activity after a while) until you interrupt
> the interpreter.  I strongly suspect this is because the output is getting
> trapped in a buffer until the command exits

No, what's happening is that the .read() is trying to
read *all* the output generated by the command... but
the "yes" command generates an infinite amount of
output! So the read() never returns.

There will be some buffering, but probably only a
few K worth. Try doing .readline() in a loop and
printing out each thing that it returns. You
should get some output very quickly.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list