simple popen question

Donn Cave donn at drizzle.com
Fri Apr 2 23:12:22 EST 2004


Quoth Jim Benson <jbenson at sextans.lowell.edu>:
| On Fri, 2 Apr 2004, Cameron Laird wrote:
...
|> In general, no; the reader doesn't control the buffering, the writer does.
|
| The reason i suspect popen is that when i run
| the executable from the unix shell...i see every
| output line ~ when expected. 

Well, the writer knows.  When you run it "from the shell", that
really means its output device is /dev/tty.  When you run it from
popen(), its output device is a pipe.  C library I/O, and hence
most application I/O, automatically treats these two devices
differently.  Or rather, it treats the tty specially, and treats
a pipe like any other file.  For the tty it uses line buffering,
for everything else block buffering.

There's a function that changes the policy - setbuffer I think may
be the contemporary standard, I think setbuf and setvbuf are historical
but don't count on me to get that straight.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list