[Baypiggies] Subprocess: Common problem/common pattern

Brent Pedersen bpederse at gmail.com
Sat Oct 2 21:55:31 CEST 2010


On Sat, Oct 2, 2010 at 12:24 PM, Brian Palmer <bpalmer at gmail.com> wrote:
> 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.

maybe i'm not doing it correctly, but i have (and had previoulsy)
tried (the equivalent of) adding fflush(stdout) to glenn's example
with no change. if you can show an example where that works, i'll
definitely be happy for the knowledge.

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

yeah, that seems to be the way to go. thanks.


More information about the Baypiggies mailing list