zsh-users
 help / color / mirror / code / Atom feed
From: Kurtis Rader <krader@skepticism.us>
To: "Benjamin R. Haskell" <zsh@benizi.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Tee all output to log file?
Date: Tue, 1 Feb 2011 16:12:22 -0800	[thread overview]
Message-ID: <282C7359-420E-4C66-84BE-A2F59FE068D7@skepticism.us> (raw)
In-Reply-To: <alpine.LNX.2.01.1102011836170.2792@hp>

In one of my scripts I wanted to run with "set -o xtrace" and capture its debug output along with the stderr of the commands run. I did this using a coprocess and some fancy fd redirection but it's far from ideal. In particular sending the data through a pipe can screw up the ordering of stdout and stderr text due to the difference in buffering the pipe introduces. To do this properly you really need to use a psuedo-tty and execute the body of the script with its stdout and stderr connected to the slave side of the psuedo-tty.

On Feb 1, 2011, at 15:41, Benjamin R. Haskell wrote:

> For scripting purposes I occasionally want a way to both record and display all the output of a script.  On several occasions now, I've looked through the output redirection section of the manual, but I never come up with quite what I'm looking for.
> 
> Essentially, when I want this, I usually want something like:
> 
> #!/bin/zsh
> (( $+logfile )) && exec |& tee $logfile
> 
> Boiled down even further, it's really just this I'm looking for:
> exec |& tee logfile
> 
> Is there something straightforward that I'm overlooking?  Is there a commonly used utility for this?  (`script` comes to mind, but I recall klunkiness when trying it in the past.)
> 
> -- 
> Best,
> Ben


  reply	other threads:[~2011-02-02  0:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 23:41 Benjamin R. Haskell
2011-02-02  0:12 ` Kurtis Rader [this message]
2011-02-02  5:23 ` gi1242+zsh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=282C7359-420E-4C66-84BE-A2F59FE068D7@skepticism.us \
    --to=krader@skepticism.us \
    --cc=zsh-users@zsh.org \
    --cc=zsh@benizi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).