From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1327 invoked from network); 4 Oct 1999 05:11:55 -0000 Received: from mail2.primenet.com.au (HELO primenet.com.au) (?OXDf3N9djCuEt/ZOu7v8zRN+BRBMP2sW?@203.24.36.6) by ns1.primenet.com.au with SMTP; 4 Oct 1999 05:11:55 -0000 Received: (qmail 24093 invoked from network); 4 Oct 1999 04:45:02 -0000 Received: from sunsite.auc.dk (130.225.51.30) by mail2.primenet.com.au with SMTP; 4 Oct 1999 04:45:02 -0000 Received: (qmail 13396 invoked by alias); 4 Oct 1999 04:42:49 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2654 Received: (qmail 13387 invoked from network); 4 Oct 1999 04:42:44 -0000 From: "Bart Schaefer" Message-Id: <991004044139.ZM309@candle.brasslantern.com> Date: Mon, 4 Oct 1999 04:41:39 +0000 In-Reply-To: Comments: In reply to Chris Hansen "Re: coproc tutorial (Re: questions)" (Oct 3, 2:08pm) References: In-Reply-To: Comments: In reply to Chris Hansen "coproc" (Oct 3, 7:01pm) X-Mailer: Z-Mail (5.0.0 30July97) To: Chris Hansen , zsh-users@sunsite.auc.dk Subject: Re: coproc tutorial (Re: questions) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 3, 2:08pm, Chris Hansen wrote: } Subject: Re: coproc tutorial (Re: questions) } } I now understan how to coproc, when is it actually the best way? } What have you used it for? To be perfectly honest, I've never used a coproc for anything except figuring out how to explain what coprocs do. I suspect they're rather more useful in other ksh-like shells because of the handling of piping into shell constructs. In zsh, a "while ...; do" loop at the right-hand-end of a pipeline is run in the current shell (unless backgrounded), so you can set and export parameters and so on and they remain set when the loop finishes. Zsh is unique in this; in other shells, such a loop would be run in a subshell. But with a coproc, you can start the left side of the "pipeline" in the coprocess and then use redirection for the input of the loop, and thus you get the loop run in the current shell. Coprocs are also useful if you ever have two commands that each want to consume the other's output: coproc command1 command2 <&p >&p I've never had reason to do that, but I suppose it would be good if you were testing a pair of network protocol daemons. The only other reason I can think of for using a coprocess would be to avoid using an "eval". Something like: if condition1; then coproc command1 elif condition2; then coproc command2 else coproc command3 fi # ... do a bunch of other setup for command4, then ... command4 <&p On Oct 3, 7:01pm, Chris Hansen wrote: } Subject: coproc } } Is there a way to write to the keyboard of a coprocess? } If not, how hard would this feature be to add? I can't answer that, as I'm completely mystified as to what "the keyboard of a coprocess" means. A coprocess is a background job; to the extent that it has "a keyboard" it would be the same one as the shell that had started it. Can you give an example of what you're trying to accomplish? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com