On Sat, 20 Apr 2024, Zachary Santer wrote:
I don't know how buffering works when stdout and stderr get redirected
to the same pipe. You'd think, whatever it is, it would have to be smart
enough to keep them interleaved in the same order they were printed to
in. That in mind, I would assume they both get placed into the same
block buffer by default.
On Sun, 21 Apr 2024, wrotycz wrote:
Sat, Apr 20, 2024 at 16:45 Carl Edquist wrote:
However, stdout and stderr are still separate streams even if they
refer to the same output file/pipe/device, so partial lines are not
interleaved in the order that they were printed.
will output "abc\n123\n" instead of "a1b2c3\n\n", even if you run it as
$ ./abc123 2>&1 | cat
It seems that it's 'interleaved' when buffer is written to a file or
pipe, and because stdout is buffered it waits until buffer is full or
flushed, while stderr is not and it doesn't wait and write immediately.
Right; my point was just that stdout and stderr are still separate streams
(with distinct buffers & buffering modes), even if fd 1 & 2 refer to the
same pipe.
Carl