stdio EOF ?

Steve Holden sholden at
Sun Aug 11 23:39:55 CEST 2002

"Jacek Generowicz" <jacek.generowicz at> wrote in message
news:tyfr8h883my.fsf at
> I'm trying to write a filter (between the GNU plotutils ode and
> graph). The problem I have is making it work in a situation like this:
>   cat | | whatever
>  (ode -f foo | | graph ... in reality)
> The desired behaviour is that I should be able to type instructions
> into standard input (which ode reacts to, sending data down the
> pipeline) which the filter should process and pass on down the
> pipeline without waiting ... but should stop when I send EOF.
> Using "for line is stdin: ..." works if all the commands are in a file
> and I do
>   cat command_file | | etc
> but in the "cat |" situation, it doesn't produce any output
> until C-d is sent.
> I guess I'm looking for a "while something(stdin)" or "while
> stdin.something" construct ...
> Any ideas ?

Probably the most significant thing you can do is run the interpreter with
the -u (unbuffered) option, to try to ensure that I/O transmission will be
as immediate as possible. When you are feeding a pipeline it's often
difficult to ensure that the input to the downstream process is delivered
exactly when you want it to be (because of buffering). Judicious use of
f.flush() can be helpful.

Steve Holden                       
Python Web Programming      

More information about the Python-list mailing list