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: Tadeus Prastowo
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 11:20:12 +0100

On Mon, Feb 5, 2018 at 1:03 AM, Peng Yu <address@hidden> wrote:
> I tried it multiple times. But the order is not guaranteed to be
> maintained, I guess it is due the buffer that might be used with awk
> when reading from stdout or stderr. So technically speaking, this
> solution does not solve my original question.
>
> --
> Regards,
> Peng

What about the following one with `-u' for unbuffered added to the sed commands?

Again, I assume that a write is atomic at line level:

exec {mystdout}>&1
coproc pA (sed -u 's%^%[From stdout] %' >&${mystdout})
coproc pB (sed -u 's%^%[From stderr] %' >&${mystdout})
coproc (echo 'Forget pB as pA has already been forgotten' >/dev/null)
cmd 1>&${pA[1]} 2>&${pB[1]}; exec {pA[1]}>&- {pB[1]}>&-

If that does not work, you can try to attach timestamp using GNU `sed'
e command and use `sort' to order your stdout based on the timestamp.
I will let you tinker with that.

--
Best regards,
Tadeus



reply via email to

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