From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16894 invoked by alias); 2 Feb 2011 00:20:10 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15757 Received: (qmail 24469 invoked from network); 2 Feb 2011 00:20:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at skepticism.us does not designate permitted sender hosts) Subject: Re: Tee all output to log file? Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Kurtis Rader In-Reply-To: Date: Tue, 1 Feb 2011 16:12:22 -0800 Cc: Zsh Users Content-Transfer-Encoding: quoted-printable Message-Id: <282C7359-420E-4C66-84BE-A2F59FE068D7@skepticism.us> References: To: "Benjamin R. Haskell" X-Mailer: Apple Mail (2.1081) 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. >=20 > Essentially, when I want this, I usually want something like: >=20 > #!/bin/zsh > (( $+logfile )) && exec |& tee $logfile >=20 > Boiled down even further, it's really just this I'm looking for: > exec |& tee logfile >=20 > 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.) >=20 > --=20 > Best, > Ben