[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: |
Greg Wooledge |
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 10:22:09 -0500 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
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.
- Re: [Help-bash] How to merge stdout and stderr yet distinguish what is from stdout and what is from stderr?, (continued)
Re: [Help-bash] How to merge stdout and stderr yet distinguish what is from stdout and what is from stderr?, Tadeus Prastowo, 2018/02/05