Questions tagged [coprocesses]
16 questions
113
votes
4 answers
How do you use the command coproc in various shells?
Can someone provide a couple of examples on how to use coproc?
slm
- 363,520
- 117
- 767
- 871
9
votes
4 answers
Run command in background with foreground terminal access
I am trying to create a function that can run an arbitrary command, interact with the child process (specifics omitted), and then wait for it to exit. If successful, typing run will appear to behave just like a bare .
If I…
John Kugelman
- 2,037
- 2
- 16
- 23
6
votes
2 answers
coproc and named pipe behaviour under command substitution
I have a requirement to make a function in a zsh shell script, that is called by command substitution, communicate state with subsequent calls to the same command substitution.
Something like C's static variables in functions (very crudely…
Phil
- 175
- 6
5
votes
2 answers
Is it possible to have multiple concurrent coprocesses?
The intent of the test script1 below is to start an "outer" coprocess (running seq 3), read from this coprocess in a while-loop, and for each line read, print a line identifying the current iteration of the outer loop, start an "inner" coprocess…
kjo
- 14,779
- 25
- 69
- 109
5
votes
2 answers
Is coproc the same as &?
I have read that $coproc < command > is different from $< command > & in that coproc will execute command in a sub-shell process.
But when I tested it, it worked just like $< command > &. The test is as follow:
First: test the behavior of $< command…
Tran Triet
- 675
- 1
- 11
- 27
5
votes
1 answer
Joined pipelines
Considering a routine such as this one:
alpha() { echo a b c |tr ' ' '\n'; }
which outputs a stream, I would like to take the output stream, transform it, and paste it with the original output stream.
If I take use upcasing as a sample…
Petr Skocik
- 28,176
- 14
- 81
- 141
3
votes
1 answer
Why does this gawk coprocess hang?
While having a go at Convert date in bash shell, I tried GNU awk's coprocess feature:
gawk -F, -v cmd='date +"%Y-%m-%d %H:%M:%S" -f-' '{print $5 |& cmd; cmd |& getline d; $5 = d}1' foo
This command hangs. I thought this might be because date is…
muru
- 69,900
- 13
- 192
- 292
2
votes
1 answer
How does bash know about its parent's coprocess in this situation, and why does a shebang line change it?
outer.sh:
ls -l /proc/$$/exe
coproc cat
./inner.sh
kill $!
inner.sh:
ls -l /proc/$$/exe
set | grep COPROC || echo No match found
coproc cat
kill $!
When I run ./outer.sh, this gets printed:
lrwxrwxrwx 1 joe joe 0 Jun 16 22:47 /proc/147876/exe ->…
Joseph Sible-Reinstate Monica
- 3,298
- 14
- 27
1
vote
1 answer
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" !=…
chemacabeza
- 89
- 5
1
vote
0 answers
Usage of cvlc with coproc
I'm trying to feed to file descriptor .mp3 files the with the dummy interface of vlc, i.e., cvlc, in order to add to a playlist on the fly or override the entire file descriptor with new data (new .mp3 file):
coproc cvlc
cvlc filename.mp3 >& OR…
amosmoses
- 11
- 1
1
vote
1 answer
How does bash coprocess achieve its pipelining?
Note this passage from man bash ( emphasis mine ):
Coprocesses
A coprocess is a shell command preceded by the coproc reserved word. A
coprocess is executed asynchronously in a subshell, as if the command
had been terminated with the & control…
Sergiy Kolodyazhnyy
- 16,187
- 11
- 53
- 104
0
votes
1 answer
Return value vs return status of a coprocess
I don't understand this sentence about Coprocesses in the bash man page:
Since the coprocess is created as an asynchronous command, the coproc command always returns success. The return status of a coprocess is the exit status of 'command'.
What…
The Quark
- 260
- 1
- 11
0
votes
0 answers
zsh, zpty: How to read the output of a process after it has exited?
Start some command with zpty:
zpty -d x ; zpty x 'echo hi' ; sleep 1
How do I read its output now that it has exited?
zpty -r x
Returns 2, and this behavior seems expected per the manpage.
HappyFace
- 1,493
- 9
- 21
0
votes
0 answers
Using coprocess to write a name referenced variable in BASH
I currently try to start background process with coproc and update a name reference variable.
My not working code:
function updateVariable(){
local -n myVar="${1}"
#i=0;
while :
do
sleep 1
myVar="ok"
#((++i))
…
kon
- 113
- 5
0
votes
1 answer
Coproc in bash script
I'm trying to do a simple shell script that will make my raspberry's bluetooth discoverable but i'm facing some issues. My raspberry is running Raspbian.
Running this through command line works perfectly:
coproc bluetoothctl
echo -e 'discoverable…
Kamigaku
- 3
- 1