zsh-users
 help / color / mirror / code / Atom feed
* Tee all output to log file?
@ 2011-02-01 23:41 Benjamin R. Haskell
  2011-02-02  0:12 ` Kurtis Rader
  2011-02-02  5:23 ` gi1242+zsh
  0 siblings, 2 replies; 3+ messages in thread
From: Benjamin R. Haskell @ 2011-02-01 23:41 UTC (permalink / raw)
  To: Zsh Users

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


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

* Re: Tee all output to log file?
  2011-02-01 23:41 Tee all output to log file? Benjamin R. Haskell
@ 2011-02-02  0:12 ` Kurtis Rader
  2011-02-02  5:23 ` gi1242+zsh
  1 sibling, 0 replies; 3+ messages in thread
From: Kurtis Rader @ 2011-02-02  0:12 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: Zsh Users

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


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

* Re: Tee all output to log file?
  2011-02-01 23:41 Tee all output to log file? Benjamin R. Haskell
  2011-02-02  0:12 ` Kurtis Rader
@ 2011-02-02  5:23 ` gi1242+zsh
  1 sibling, 0 replies; 3+ messages in thread
From: gi1242+zsh @ 2011-02-02  5:23 UTC (permalink / raw)
  To: zsh-users; +Cc: Benjamin R. Haskell

On Tue, Feb 01, 2011 at 06:41:26PM -0500, Benjamin R. Haskell wrote:

> Boiled down even further, it's really just this I'm looking for:
> exec |& tee logfile

How about

    exec >& /dev/tty >& logfile

when multios is set.

GI

-- 
'Ethernet' -- Something used to catch the etherbunny.


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

end of thread, other threads:[~2011-02-02  5:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-01 23:41 Tee all output to log file? Benjamin R. Haskell
2011-02-02  0:12 ` Kurtis Rader
2011-02-02  5:23 ` gi1242+zsh

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).