bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ...Limitation?


From: Paul Jarc
Subject: Re: ...Limitation?
Date: Tue, 26 Sep 2006 11:45:42 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)

mwoehlke <mwoehlke@tibco.com> wrote:
> I am trying to figure out how to run a command and pipe the output 
> through tee, and then check the status of the original command.

This uses a bash-specific feature:
cmd > >(tee file); status=$?

This should work on any sh:
exec 3>&1 && status=`exec 4>&1 && { cmd; echo $? >&4; } | tee file >&3`

Or, if you don't want to clobber any descriptors, in case they might
be in use for something else:
: > file &&
{ tail -f file & } &&
pid=$! &&
{ cmd > file; status=$?; } &&
sleep 1 && # give tail a chance to print the last bits that were just written
kill "$pid"


paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]