bug-bash
[Top][All Lists]
Advanced

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

Re: ...Limitation?


From: mwoehlke
Subject: Re: ...Limitation?
Date: Tue, 26 Sep 2006 13:00:12 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.0

Paul Jarc wrote:
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=$?

Thanks Paul and Stephen for the replies. I am using bash, so the above solution is fine, and is working.

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"

--
Matthew
Download. Untar. Configure. Make. Install. Lather. Rinse. Repeat.





reply via email to

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