Skip to main content
deleted 1 character in body
Source Link

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; } [1] 95244 $ echo 'ls -l; echo EOD' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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; } [1] 95244 $ echo 'print("hello"); print("EOD");' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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 wouldwill be appreciated.

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; } [1] 95244 $ echo 'ls -l; echo EOD' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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; } [1] 95244 $ echo 'print("hello"); print("EOD");' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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 would be appreciated.

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; } [1] 95244 $ echo 'ls -l; echo EOD' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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; } [1] 95244 $ echo 'print("hello"); print("EOD");' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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.

Source Link

Bash coproc with python

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; } [1] 95244 $ echo 'ls -l; echo EOD' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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; } [1] 95244 $ echo 'print("hello"); print("EOD");' >&"${MY_BASH[1]}" $ is_done=false; while [[ "$is_done" != "true" ]]; do > read var <&"${MY_BASH[0]}" > 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 would be appreciated.