Questions tagged [coproc]

19 questions
10
votes
3 answers

bash coproc and leftover coproc output

I need to read some configuration data into environment variables in a bash script. The "obvious" (but incorrect) pattern is: egrep "pattern" config-file.cfg | read VAR1 VAR2 VAR3 etc... This fails because the read is run in a subshell and…
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
7
votes
1 answer

How to use 'coproc' to interact with another command driven program

Ok, obviously I am NOT a bash guru and am in need of one! I have never used 'coproc' before, but it seems to be just what I need. But, I have to admit that I can not extrapolate from the various 'ping' examples out there! [I did try for a couple…
JoeG
  • 7,191
  • 10
  • 60
  • 105
4
votes
2 answers

More coproc questions

This is a followup to bash coproc and leftover coproc output The idiom I finally settled on for processing a file one line at a time is: coproc cat auto/etc/build.cfg while read -u ${COPROC[0]} BRANCH TARGET SVNSRC SVNTAG BUILDTYPE DISTTYPE…
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
4
votes
2 answers

Background process redirect to COPROC

In the following test script I run an elementary coprocess to which the echo built-in, run in background, attaches its standard-output: #!/bin/bash # TEST 1 coproc /bin/sleep 100 echo >&${COPROC[1]} & The script always fails, for no apparent…
davide
  • 2,082
  • 3
  • 21
  • 30
2
votes
1 answer

How to add shell commands while executing psql in shellscript

Currently I'm writing a shell script that do batch job on the database and I want to put shell script action like write to log file or rollback in some condition while executing psql. Like this ConnectDb() { PGPASSWORD=postgres psql -U postgres…
2
votes
1 answer

'wait $COPROC_PID' doesn't wait

The following test script: #!/bin/bash f() { :; } while :; do coproc f par1 wait $COPROC_PID done floods the console with: ./debug.sh: line 7: warning: execute_coproc: coproc [8740:COPROC] still exists ./debug.sh: line 7: warning:…
davide
  • 2,082
  • 3
  • 21
  • 30
1
vote
1 answer

client using coproc does not exit

I have a filter like: #!/bin/bash while read line do echo $line | tr "B" "b" done I have a client that use that filter using coproc like: #!/bin/bash coproc ./filter echo Bogus >&"${COPROC[1]}" cat <&"${COPROC[0]}" Now the client does not exit.…
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
1
vote
3 answers

Start and Stop Process in Bash Script

I am looking for a clean method to start and stop java processes based on stdout. Basically I want to go through a for loop in Bash that starts a java command with input variables, monitors stdout for a specific string "Results:" and then kills…
Chris Moretti
  • 585
  • 3
  • 13
  • 31
1
vote
1 answer

How to use coproc on Mac OS X 11?

I'm trying to cross io between two processes and coproc does not seem to be installed in OS X 10.11.x. I get: bash: coproc: command not found My bash version is: GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin15.3.0) How can I install…
Rodrigo
  • 131
  • 2
  • 6
1
vote
1 answer

Accessing a coprocess outside of the bash script that creates it

So I'm using the coproc command in a script to run a java program and to feed input to it, as follows: #!/bin/bash echo Script started. coproc java -jar MultiThreadedFileProcessor.jar echo start >&${COPROC[1]} echo Script terminated. I'd like to…
Mistborn
  • 11
  • 2
1
vote
1 answer

Nested coprocess variable in bash

I would like to know how can I use nested variables in a coprocess.For example, I can use a nested variable in the following way normally. $ a=b $ b=lol $ echo ${!a} lol But I can't do this for a coprocess, at least in shell script: $ coproc a {…
1
vote
2 answers

Alternatives to coproc and sub-process redirection (Bash 3)

Okay, so I'm in a situation where I'd really like to be using either a co-process via coproc or via redirection such as <(some command), but unfortunately I'm limited to bash 3.2 in one of the my target environments, which means I'm limited in what…
Haravikk
  • 3,109
  • 1
  • 33
  • 46
1
vote
1 answer

Line buffering in a bash coproc

I'm trying to use a bash coproc and I'm running into difficulties, most likely with buffering. I have a complex command which accepts line-oriented input from stdin and prints a line to stdout, per line of input. At the command-line this command…
Digital Trauma
  • 15,475
  • 3
  • 51
  • 83
0
votes
1 answer

bash coproc - unexpected behavior

Followup to More coproc questions bash coproc and leftover coproc output Given that the obvious use of coproc does not work as I expected, as seen in: $ cat test.sh coproc cat auto/etc/build.cfg while read -u ${COPROC[0]} BRANCH TARGET SVNSRC…
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
0
votes
1 answer

"${COPROC[0]}"/"${COPROC[1]}": Bad file descriptor

I have a script which i am using as a filter: #!/usr/bin/env gjs const { Gio } = imports.gi; let file = Gio.File.new_for_path(ARGV[0]); let fileInfo = file.query_info('*', Gio.FileQueryInfoFlags.NONE, null); let icons =…
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
1
2