[-- Attachment #1: Type: text/plain, Size: 456 bytes --] Hello all! Is there a simpler way to additionally log stdout/stderr to a file, while keeping the existing one? { echo stdout; >&2 echo stderr } > /tmp/log > /dev/tty 2> /tmp/err 2>/dev/tty Will log stdout to stdout and /tmp/log, for example. Specifically, I want to be able to do this for the remainder of the process via "exec". The goal is to have an interactive stdio like normal, but also log all stdout / stderr to a log file. *Zach Riggle* [-- Attachment #2: Type: text/html, Size: 793 bytes --]
Why not use the script command instead?
On Tue, 10 May 2022 14:20:59 -0400,
Zach Riggle wrote:
>
> [1 <text/plain; UTF-8 (7bit)>]
> Hello all!
>
> Is there a simpler way to additionally log stdout/stderr to a file, while
> keeping the existing one?
>
> { echo stdout; >&2 echo stderr } > /tmp/log > /dev/tty 2> /tmp/err
> 2>/dev/tty
>
> Will log stdout to stdout and /tmp/log, for example.
>
> Specifically, I want to be able to do this for the remainder of the process
> via "exec". The goal is to have an interactive stdio like normal, but also
> log all stdout / stderr to a log file.
>
> *Zach Riggle*
> [2 <text/html; UTF-8 (quoted-printable)>]
--
Your life is like a penny. You're going to lose it. The question is:
How do
you spend it?
John Covici wb2una
covici@ccs.covici.com
On Tue, May 10, 2022 at 11:21 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> Is there a simpler way to additionally log stdout/stderr to a file, while keeping the existing one?
Your best bet for that may be to use something like the "script"
command, or see if your terminal emulator can keep a log.
There is a long-standing bug with using multios with a "naked exec"
... but that will be fixed as of the 5.9 release, at which point
you'll be able to do e.g.:
exec 2>/tmp/err 2>/dev/tty
The drawback to this is that the background process that manages the
two outputs is not synchronized with ZLE, so you may not see the full
output as soon as you expect and/or the next prompt may be mixed into
the output. The prompts themselves don't go to stdout or stderr,
either.
You can garble this a bit less by setting up something with "zle -F"
to watch for text appearing in the log file, but you have to do so
carefully to avoid deadlock if the volume of output exceeds the OS's
internal I/O buffer space.