simple popen question

Cameron Laird claird at lairds.com
Sat Apr 3 05:39:41 EST 2004


In article <1080965541.46978 at yasure>, Donn Cave <donn at drizzle.com> wrote:
>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

All true--and Python even has an answer, Pexpect, for those stuck
with such subtleties.  I repeat my advice, though, that Mr. Benson
will likeliest find quick satisfaction simply by having his writer
flush on newline.

Also, Mr. Benson, are you *sure* you want to treat blank lines as
end-of-message markers?
-- 

Cameron Laird <claird at phaseit.net>
Business:  http://www.Phaseit.net



More information about the Python-list mailing list