[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About using COPROC
From: |
Peng Yu |
Subject: |
Re: About using COPROC |
Date: |
Fri, 2 Apr 2021 16:47:30 -0500 |
On Fri, Apr 2, 2021 at 4:11 PM Marco Ippolito <maroloccio@gmail.com> wrote:
>
> > But if I run the following script. I don't quite understand why the
> > following does not work but the previous one works? Could anybody help
> > explain coproc?
>
> The coproc ends and the file descriptors are closed. The array is unset.
>
> You are _racing_ your coproc.
>
> Try adding a `sleep` inside the coproc command group, before `seq`.
>
> Does it work then?
By adding a longer sleep time, the following script works. But why the
coprocess is not halt to wait for its output to be taken? This
behavior is counterintuitive.
coproc {
sleep 2
seq 3
}
sleep 1
while IFS= read -r -u "${COPROC[0]}" line; do
builtin printf '%s\n' "$line"
done
--
Regards,
Peng