[Baypiggies] Subprocess: Common problem/common pattern

Brian Palmer bpalmer at gmail.com
Sat Oct 2 21:24:05 CEST 2010

On Sat, Oct 2, 2010 at 11:05 AM, Brent Pedersen <bpederse at gmail.com> wrote:

> i've had this problem as well. by my reading of the docs, you're
> supposed to be able to get line-buffered output by setting bufsize=1,
> but it seems there's some minimum number of characters that needs to
> get sent as well. i can make your example show incrementally in python
> by adding a hacky line to your c code:
>        for (j = 0; j < 16384; j++){ printf(" "); }

You have to consider buffering on both the input and output sides of a pipe.
By default, your C library is probably buffering stdout in a pipeline to
some large blocksize.
If you changed the printf statements to be fprintf(stderr,  ...) instead,
you probably wouldn't need do that; by default, stderr will be flushed after
each newline. To work around this,
the calling process can set up a pseudo-tty to "fool" the executing program
into thinking it's not in a pipeline. This is just one of the things that
pexpect can offer you. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101002/db6a05af/attachment.html>

More information about the Baypiggies mailing list