[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Buffering in standard streams
On Thu, 21 May 2015 12:30:21 +0200
Pierre Pronchery <khorben%defora.org@localhost> wrote:
> I just read this nice article from a coreutils maintainer:
In case it affects the discussion, note that
$ printf "one\ntwo\nthree\n" | ( sed 1q ; sed 1q ; sed 1q )
As you can see the first sed process reads all the data,
starving the rest.
is incorrect. Nothing is "starved"; the second and third sed are never
invoked because the first one terminates the pipeline when it
encounters the first newline. Furthermore they are not *in* the
pipeline and never see any input. Cf:
$ printf "one\ntwo\nthree\n" | ( sed 1d ; nl )
$ printf "one\ntwo\nthree\n" | ( sed 1d | sed 1d | nl )
The example using ssh is similarly flawed.
That said, ISTM Buehler's first suggestion, an environment variable, is
the best option.
I have occasionally wanted to control stdio buffering, and I'm not
persuaded by Ulrich's argument against having libc honor an environment
variable. A utility like stdbuf can no more "set up the environment
properly" than can an environment variable, because both rely on the
user's understanding about which file descriptors will be used.
I would use a syntax like:
stdout, line buffered
Main Index |
Thread Index |