zsh-users
 help / color / mirror / code / Atom feed
* Multios redirection while keeping current descriptors, and exec
@ 2022-05-10 18:20 Zach Riggle
  2022-05-10 18:49 ` John Covici
  2022-05-10 18:54 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: Zach Riggle @ 2022-05-10 18:20 UTC (permalink / raw)
  To: Zsh Users

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Multios redirection while keeping current descriptors, and exec
  2022-05-10 18:20 Multios redirection while keeping current descriptors, and exec Zach Riggle
@ 2022-05-10 18:49 ` John Covici
  2022-05-10 18:54 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: John Covici @ 2022-05-10 18:49 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Multios redirection while keeping current descriptors, and exec
  2022-05-10 18:20 Multios redirection while keeping current descriptors, and exec Zach Riggle
  2022-05-10 18:49 ` John Covici
@ 2022-05-10 18:54 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2022-05-10 18:54 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-10 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 18:20 Multios redirection while keeping current descriptors, and exec Zach Riggle
2022-05-10 18:49 ` John Covici
2022-05-10 18:54 ` Bart Schaefer

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).