simple popen question

Jim Benson jbenson at sextans.lowell.edu
Sat Apr 3 11:25:24 EST 2004


On Sat, 3 Apr 2004, Cameron Laird wrote:

> 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.
> >|
> >
> >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.
> >
> 
> 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.

Thanks to all...i understand what is going on much better now.
I'll try your advice Mr. Laird and add a flush to the write
side. It sounds like that is what i want.

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

Perhaps not...but it seems to work. It doesn't stop on
lines that contain only a '\n\0' for example. Hence
on the write side i can print out apparently blank lines..
to make the reading of the output easier....and the 
readline loop keeps piping them and only stops when the
executable stops. 

Thanks again,

Jim 





More information about the Python-list mailing list