zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Chris Hansen <chris@phred.mine.nu>, zsh-users@sunsite.auc.dk
Subject: Re: coproc tutorial (Re: questions)
Date: Mon, 4 Oct 1999 04:41:39 +0000	[thread overview]
Message-ID: <991004044139.ZM309@candle.brasslantern.com> (raw)
In-Reply-To: <Pine.LNX.4.10.9910031404110.8139-100000@PHRED.dancris.com>
In-Reply-To: <Pine.LNX.4.10.9910031857520.10533-100000@PHRED.dancris.com>

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


  reply	other threads:[~1999-10-04  5:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-03  8:30 questions Chris Hansen
1999-10-03 11:10 ` questions Stefan Berglund
1999-10-03 17:18   ` questions Bart Schaefer
1999-10-03 18:45   ` coproc tutorial (Re: questions) Bart Schaefer
1999-10-03 21:08     ` Chris Hansen
1999-10-04  2:01     ` coproc Chris Hansen
1999-10-04  4:41       ` Bart Schaefer [this message]
1999-10-04  5:21         ` coproc tutorial (Re: questions) Chris Hansen
1999-10-04  6:22           ` Bart Schaefer
1999-10-04 16:10 Jay Sekora
1999-10-04 18:42 ` Bart Schaefer
1999-10-11 10:45 Sven Wischnowsky
1999-10-11 12:55 ` Thomas Köhler
1999-10-12  6:53 Sven Wischnowsky
1999-10-12  8:42 ` Thomas Köhler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=991004044139.ZM309@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=chris@phred.mine.nu \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).