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: John Kearney
Subject: Re: [Help-bash] How to merge stdout and stderr yet distinguish what is from stdout and what is from stderr?
Date: Tue, 6 Feb 2018 09:34:53 +0100

There is a small tool called "logapp" that can do this, realising it in a
bash script is not really worth the hassle.

On Mon, Feb 5, 2018 at 5:25 PM, Tadeus Prastowo <address@hidden>
wrote:

> On Mon, Feb 5, 2018 at 4:22 PM, 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.
>
> Then, timestamping won't help either, will it?  Suppose cmd output
> line L at time t_1 at stdout and were still be able to output line L'
> at time t_1+D at stderr.  The scheduler then happened to decide that
> the process waiting at stderr were to go first.  So, the process
> stamped L' with time t_1+D+D'.  Afterwards, the scheduler gave the
> processor to the process waiting at stdout, which would stamp L with
> time t_1+D+D'+D''.  So, the correct relative order of L and L' as
> output by cmd is screwed because by their timestamps, L' would be
> ordered before L.
>
> --
> Best regards,
> Tadeus
>
>


reply via email to

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