Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tee all output to log file?
- X-seq: zsh-users 15757
- From: Kurtis Rader <krader@xxxxxxxxxxxxx>
- To: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- Subject: Re: Tee all output to log file?
- Date: Tue, 1 Feb 2011 16:12:22 -0800
- Cc: Zsh Users <zsh-users@xxxxxxx>
- In-reply-to: <alpine.LNX.2.01.1102011836170.2792@hp>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author