[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to safely pipe output to tee?
From: |
Micah Cowan |
Subject: |
Re: How to safely pipe output to tee? |
Date: |
Mon, 07 Mar 2011 11:02:51 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 |
(03/07/2011 10:31 AM), Steven W. Orr wrote:
> I want to compute a command string which will end up in foo.
>
> Then I want to run that command and cause stdout and stderr to be piped
> to tee for safe keeping while it also goes to the screen.
>
> After the command finishes, I need tee to exit.
>
> It sounds easy, but it's not.
>
> eval "$foo" 2>&1 | tee filename
>
> will cause a hang. Why? Because what $foo does is to start lots of child
> processes and services which do not end. I just want to proceed to the
> next command as soon as $foo completes.
It seems to me that tee hangs around because its pipe is still open on
the other end (courtesy of these background processes you mention).
In that case, can't you just redirect all these background processes, so
that they're not writing to that same stdout file descriptor?
For instance,
foo='sleep 100 &'
poses an issue, but
foo='sleep 100 >&- 2>&- &'
shouldn't.
--
HTH,
Micah J. Cowan
http://micah.cowan.name/