help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coproc issue


From: Greg Wooledge
Subject: Re: coproc issue
Date: Sat, 17 Jun 2023 10:41:30 -0400

On Sat, Jun 17, 2023 at 03:15:48PM +0200, alex xmb ratchev wrote:
> whats the problem here
> some timing issues ?
> 
> ~ $ coproc a { echo foo ; read foo ; echo $foo ; } ; cat <&$a ; echo bar
> >&${a[1]}
> [2] 13957
> foo
> 
> ^C

It's not clear what you expected.  You've launched a coproc, which is
a background process.  This coproc writes "foo" to stdout, and then
performs a blocking read, which will wait for a line to be sent to its
stdin.

After launching the coproc, you run a "cat" process which reads from
the coproc's output and relays it to the screen.  Thus, you see the
"foo" which the coproc wrote, and is subsequently written by cat, to
the terminal.

However, cat doesn't terminate until an EOF occurs.  Your coproc is
still "running" (waiting on a blocking read), and therefore it has
not closed its output.  This means the pipe that cat is reading from
is still there, still ready to deliver more data.  It has not been
closed, and therefore there's no EOF, and therefore cat does not exit.

So, any commands that occur *after* cat do not get executed.

If you want to interact with a coproc, you need to use commands that
don't wait for EOF.  Use read instead of cat, for example.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]