I am playing with the
coproc
of Bash and I am failing to understand something.
I started with the following example:
# Example#1
$ coproc MY_BASH { bash; }
95244
$ echo 'ls -l; echo EOD' >&"${MY_BASH}"
$ is_done=false; while [[ "$is_done" != "true" ]]; do
> read var if [[ $var == "EOD" ]]; then
> is_done="true"
> else
> echo $var
> fi
> done
total 0
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file10.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file1.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file2.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file3.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file4.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file5.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file6.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file7.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file8.txt
-rw-rw-r-- 1 username username 0 Nov 11 13:00 file9.txt
$
Here we can see that the current Bash shell is able to create a coprocess and interact with it.
# Example 2
In this case, I switch from a bash
coprocess to a python
coprocess:
$ coproc MY_BASH { python; }
95244
$ echo 'print("hello"); print("EOD");' >&"${MY_BASH}"
$ is_done=false; while [[ "$is_done" != "true" ]]; do
> read var if [[ $var == "EOD" ]]; then
> is_done="true"
> else
> echo $var
> fi
> done
In this scenario the program hangs and gets blocked.
I have the impression that I am forgetting to send something in the input.
Any help to better understand what is going on will be appreciated.
Asked by chemacabeza
(89 rep)
Nov 11, 2022, 12:13 PM
Last activity: Apr 14, 2023, 10:13 PM
Last activity: Apr 14, 2023, 10:13 PM