help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to merge stdout and stderr yet distinguish what is f


From: Russell Lewis
Subject: Re: [Help-bash] How to merge stdout and stderr yet distinguish what is from stdout and what is from stderr?
Date: Mon, 5 Feb 2018 09:29:15 -0700

I agree with you, Greg about the race condition.

However, I'd quibble about your last paragraph just a hair: if you have the
ability to modify the source application so as to change how it prints
output, then it's easy to solve this problem - just annotate the output as
the original poster desired.  :)

Russ

On Mon, Feb 5, 2018 at 8:22 AM, Greg Wooledge <address@hidden> wrote:

> On Mon, Feb 05, 2018 at 03:31:12PM +0100, Tadeus Prastowo wrote:
> > On Mon, Feb 5, 2018 at 2:54 PM, Greg Wooledge <address@hidden>
> wrote:
> > > On Sun, Feb 04, 2018 at 06:03:37PM -0600, Peng Yu wrote:
> > >> I tried it multiple times. But the order is not guaranteed to be
> > >> maintained,
> > >
> > > Correct!  THAT is the real issue here.
> >
> > Won't `stdbuf' help?
>
> No, because it's not a buffering issue.  It's a race condition.
>
> When you take stream A and run it through filter program A, filter
> program A introduces some nondeterministic delay between the time the
> input is received and the time the filtered output is written.
>
> Then you take stream B and run it through filter program B, which
> introduces *its* own delay.
>
> If the delay of line 1 (stream A) is just a few milliseconds longer
> than expected for any reason, then it may occur *after* line 2
> (stream B) is written.
>
> If you want to work around that, you could timestamp each line in
> addition to filtering it, and then run both timestamped-and-filtered
> streams through a third program that merges the lines back into the
> correct order by using the timestamps, and then removes the timestamps.
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]