bug-bash
[Top][All Lists]
Advanced

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

Re: How to safely pipe output to tee?


From: Steven W. Orr
Subject: Re: How to safely pipe output to tee?
Date: Mon, 07 Mar 2011 15:22:26 -0500
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9

On 3/7/2011 2:02 PM, Micah Cowan wrote:
(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.


Sorry, but I'm not sure I see why this helps.

I think it says (I assume you meant a space between the 100 and the greater than, otherwise you're just trying to close channel 100):

foo='sleep 100 >&- 2>&- &'

"Sleep for 100 seconds and then close channel 1 and channel 2."

Maybe. But how do I harvest the status of the command, since the sleep will always succeed?

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



reply via email to

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