From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9113 invoked from network); 4 May 1998 01:43:39 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 4 May 1998 01:43:39 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id VAA16250; Sun, 3 May 1998 21:36:06 -0400 (EDT) Resent-Date: Sun, 3 May 1998 21:35:54 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980503183549.ZM1342@candle.brasslantern.com> Date: Sun, 3 May 1998 18:35:49 -0700 In-Reply-To: <19980503181509.09250@astaroth.nit.gwu.edu> Comments: In reply to Sweth Chandramouli "Re: Re: exit value of intermediate program in pipe" (May 3, 6:15pm) References: <199805022224.QAA03113@ipecac.Central.Sun.COM> <980502190831.ZM29269@candle.brasslantern.com> <19980503021749.21621@astaroth.nit.gwu.edu> <980503023014.ZM31001@candle.brasslantern.com> <19980503181509.09250@astaroth.nit.gwu.edu> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sweth Chandramouli , zsh-users@math.gatech.edu Subject: Re: exit value of intermediate program in pipe MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"upP-A.0.Jz3.vjHJr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1504 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On May 3, 6:15pm, Sweth Chandramouli wrote: : Subject: Re: Re: exit value of intermediate program in pipe : : in ksh i would do : : { : grep -v bar |& : print -p `/bin/blah ; exitstatus=$?` : read -p output : echo $output : return $exitstatus : } You can do exactly that same thing, except insted of grep -v bar |& You'd say coproc grep -v bar Both print -p and read -p are the same in zsh as in ksh. Of course, you probably want while read -p output do print -r $output done as each read consumes only one line, not the entire stream. : for zsh, would i just do : : { : grep -v bar coproc | : >&p `/bin/blah ; exitstatus=$?` That line doesn't do what you think. What you'd want is just /bin/blah >&p exitstatus=$? : <&p output ; echo $output That's not right either. You'd probably need cat <&p and you'd probably have to start it before you started /bin/blah, if blah could potentially produce more than a few kbytes of output. : return $exitstatus : } The last problem is that grep won't exit until it sees EOF on its stdin, but >&p dups the coproc input without actually closing it. So the grep won't get EOF when blah exits. You have to shut it down some other way; the only thing I've found is to start another coprocess. I don't know if this is a bug, or what. So you get { coproc grep -v bar cat <&p & /bin/blah >&p exitstatus=$? coproc exit # Shuts down grep by closing its input, as # a side-effect of starting a new coproc # which then immediately exits. Ewww. wait # Allows cat to finish, just in case. return $exitstatus } I think { /bin/blah >>(grep -v bar) } is a lot nicer, don't you? : what zsh really needs is something like the hawksbill book from : oreilly for ksh, that gives a lot of examples and compares it to other : shells There's a lot of that in the FAQ, found in Etc/FAQ in the zsh dist. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com