* coproc problem when input closed but output open
@ 2011-03-15 19:04 Rory Mulvaney
2011-03-16 14:57 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Rory Mulvaney @ 2011-03-15 19:04 UTC (permalink / raw)
To: zsh-users
Thanks for the tip involving calling coproc exit at the begnning of a
coproc shell function, I think using coproc that way is really useful.
Now I'm having trouble with another example, where the coproc doesn't
return without killing it. Maybe the problem has something to do with the
output file descriptor of the coproc still being open. But shouldn't the
coproc finish writing its output and exit?
Thanks,
Rory M.
function wcFunc() {
coproc exit
wc
}
coproc wcFunc
wcf=$!
# copy the write and read fd's for the coproc
exec 5>&p 6<&p
# start another null coproc to get a new target for the p fd
coproc exit
# copy output of coproc to stdout
cat <&6 &
exec 6<&-
echo hi there >&5
# close the fd, so hopefully the coproc would exit, but it doesn't
exec 5>&-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: coproc problem when input closed but output open
2011-03-15 19:04 coproc problem when input closed but output open Rory Mulvaney
@ 2011-03-16 14:57 ` Bart Schaefer
2011-03-17 21:17 ` Rory Mulvaney
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2011-03-16 14:57 UTC (permalink / raw)
To: zsh-users
On Mar 15, 2:04pm, Rory Mulvaney wrote:
}
} Now I'm having trouble with another example, where the coproc doesn't
} return without killing it. Maybe the problem has something to do with the
} output file descriptor of the coproc still being open. But shouldn't the
} coproc finish writing its output and exit?
You still have "cat <&6 &" running in the background. That has a copy of
the coproc's stdin (fd5) open, because it inherited all the descriptors
of the parent shell and fd5 is not specially closed the way the "p"
descriptor is. You can use
cat <&6 5>&- &
to be sure cat doesn't inherit fd5.
It might be clearer if you restructure the code to be:
coproc wcFunc
wcf=$!
# copy output of coproc to stdout
cat <&p &
# copy the write and read fd's for the coproc
exec 5>&p 6<&p
exec 6<&-
# start another null coproc to get a new target for the p fd
coproc exit
Then you don't need to fiddle with fd5 when starting the cat.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: coproc problem when input closed but output open
2011-03-16 14:57 ` Bart Schaefer
@ 2011-03-17 21:17 ` Rory Mulvaney
0 siblings, 0 replies; 3+ messages in thread
From: Rory Mulvaney @ 2011-03-17 21:17 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Thanks.
On Wed, 16 Mar 2011, Bart Schaefer wrote:
> You still have "cat <&6 &" running in the background. That has a copy of
> the coproc's stdin (fd5) open, because it inherited all the descriptors
> of the parent shell and fd5 is not specially closed the way the "p"
> descriptor is. You can use
>
> cat <&6 5>&- &
>
> to be sure cat doesn't inherit fd5.
>
> It might be clearer if you restructure the code to be:
>
> coproc wcFunc
> wcf=$!
>
> # copy output of coproc to stdout
> cat <&p &
>
> # copy the write and read fd's for the coproc
> exec 5>&p 6<&p
> exec 6<&-
>
> # start another null coproc to get a new target for the p fd
> coproc exit
>
> Then you don't need to fiddle with fd5 when starting the cat.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-17 21:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-15 19:04 coproc problem when input closed but output open Rory Mulvaney
2011-03-16 14:57 ` Bart Schaefer
2011-03-17 21:17 ` Rory Mulvaney
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).