On Wed, Jan 12, 2011 at 3:40 PM, Mike Miller
<mbmiller+l at gmail.com<mbmiller%2Bl at gmail.com>
> wrote:

>
> Regarding the system for keeping separate .out and .err files:  I find
> that the order of appearance on the terminal changes if the stderr and
> stdout are produced at almost the same time:
>
> $ ( echo "stdout1" ; echo "stderr1" 1>&2 ; echo stdout2 )
> stdout1
> stderr1
> stdout2
>
> So stderr was second, but here it is first:
>
>
> $ ( ( ( echo "stdout1" ; echo "stderr1" 1>&2 ; echo stdout2 ) | tee foo.out
> ) 2>&1 1>&3 ) 3>&2 | tee foo.err
> stderr1
> stdout1
> stdout2
>
> Adding a few milliseconds between makes it come out in order:
>
> $ ( ( ( echo "stdout1" ; sleep .01 ; echo "stderr1" 1>&2 ; sleep .01 ; echo
> stdout2 ) | tee foo.out ) 2>&1 1>&3 ) 3>&2 | tee foo.err
> stdout1
> stderr1
> stdout2
>
>

When you have two separate buffered streams going to the same file, there
are no guarantees the temporal order will be preserved.  The bits hit the
file when the buffers are flushed by the kernel.  If you're debugging a
program that sends errors to stderr and output to stdout, an error message
may appear well after the output on stdout that it was meant to be
associated with.

-Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20110112/76430820/attachment.htm