Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Redirecting shell output to a pipe
- X-seq: zsh-users 14606
- From: "Nadav Har'El" <nyh@xxxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: Redirecting shell output to a pipe
- Date: Wed, 25 Nov 2009 16:15:32 +0200
- Cc: zsh-users@xxxxxxx
- Hebrew-date: 8 Kislev 5770
- In-reply-to: <20091125123743.79814faa@news01>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20091124143140.GA7612@xxxxxxxxxxxxxxxxxxxxxxxxxx> <4B0C2709.5080307@xxxxxxx> <20091125064801.GA8371@xxxxxxxxxxxxxxxxxxxxxxxxxx> <20091125123743.79814faa@news01>
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.
Beautiful!
> 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).
Thanks,
Nadav.
--
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