Greg Klanderman writes:
I hope there's someone on this list who can easily answer this
question off the top of their head. I'm thinking about re-writing the
parsing in pcl-cvs to parse stdout and stderr simultaneously,
rather than separately. I think this would make it much more robust.
Anyway the question is, if I redirect stdout and stderr as follows
(in /bin/sh):
% some_command > output.txt 2>&1
am I guaranteed that output to stdout and stderr by the program is
synchronized? Do the two output streams share the same buffer? I
think so, but would like to be certain before undertaking a change
to pcl-cvs.
From "man setbuffer" on my FreeBSD box:
Normally all files are block buffered. When the first I/O
operation oc-
curs on a file, malloc(3) is called, and an optimally-sized buffer is ob-
tained. If a stream refers to a terminal (as stdout normally does) it is
line buffered. The standard error stream stderr is always unbuffered.
I have a vague recollection of this being the case under
certain other Unices as well... so I guess the answers are no, and no.
//Raymond.