Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Tee all output to log file?



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