Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Redirecting shell output to a pipe

On Wed, Nov 25, 2009, Peter Stephenson wrote about "Re: Redirecting shell output to a pipe":
> > > > be able to redirect the scripts output to a pipe? E.g., a very useful
> > > > idiom could have been
> > > >
> > > > 	exec | tee filename
> different parts of the pipeline, then wait for them to finish.  What you
> want is beyond the limits of expression of the standard pipeline syntax:
> you want it to say create this pipeline and leave it running as a separate
> process with output redirected.
> Zsh does have a syntax for exactly that:
> exec > >(tee filename)
> That might do what you want.


> Note the "tee" process is asynchronous with respect to the rest of the
> script, i.e. the shell won't wait for it to exit before the script exits.
> That's normally the case with pipelines; the second process waits for the
> first to exit.  I'm noting it specially here because it's perhaps less
> clear that the shell is becoming the first part of a pipeline over which it
> has no overall control, i.e. that it's different from running a pipeline
> entirely within the shell.  But it may already be obvious that's the case.

Yes, my "coproc"-based solution also suffered from a related problem -
sometimes you lose the last line of output because the shell exited
(and killed the tee process) before it had the time to do its output.
I wonder, though, here, whether the shell will actually kill the tee or will
it continue to live forever (I didn't test).


Nadav Har'El                        |    Wednesday, Nov 25 2009, 8 Kislev 5770
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Attention: There will be a rain dance
http://nadav.harel.org.il           |Friday night, weather permitting.

Messages sorted by: Reverse Date, Date, Thread, Author