My pipe flushes late

Eric Blake
Wed Aug 20 12:07:00 GMT 2008

Hash: SHA1

Let's hope your plumbing doesn't overflow.  Although the hippos might like
the smell...

According to Robert Schmidt on 8/20/2008 5:54 AM:
> I basically need to pass some output through d2u, then add a prefix to
> each line.  Most importantly, I need the line to flush through the pipe
> immediately.  However, d2u (or the pipe itself) caches/flushes late.

What you want is to convert d2u's stdout from fully buffered (default, as
per POSIX, for all non-interactive file descriptors) to line-buffered or
unbuffered.  On Linux, this can be done with an LD_PRELOAD of a library
that calls setvbuf prior to letting main() run, but I'm not sure cygwin
quite has those hooks.  The coreutils list has even seen a proposal for
adding an app just for this purpose, although it is yet to materialize:

At this point, your best bet is to use something that presents d2u with a
pty as stdout (thus output would be line-buffered), rather than a pipe,
then consumes the pty output and throws it over the wall to the original
pipe to sed with flushing.  Have you tried expect - according to the link
above, expect provides a script unbuffer that does just what I described?

- --
Don't work too hard, make some time for fun as well!

Eric Blake   
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


More information about the Cygwin-talk mailing list