I searched a bit on how to do this, but I cannot find a solution. I am using process substitution cause of necessity. I want to wait for all the processing to finish before proceeding.
How do I get the PID of my 'runner' FUNCTION below so I can wait for it?
Basically what it does is execute, then log the stdout, then log errors & errors to stdout. Works well except for the out of sequence responses.
"${@}" 1> >(2log) 2> >(2log2scr | tee >&2) pid=???? # <<< HERE while [ -e /proc/"$pid" ]; do sleep 0.1; done # <<< HERE I tried things like the following but does not work:
pid=$(exec sh -c "${@}" 1> >(2log) 2> >(2log2scr | tee >&2) )
this works partially - it breaks my EVAL:
> runner success & > while [ -e /proc/$! ]; do sleep 0.1; doneOUTPUTS
started running FAILURE: **** 4.4.19(1)-release **** finished running EVAL IS:
Your help is appreciated.
The full script follows if you need it for testing:
#!/bin/bash logfile='test.log' logprep() { local in=$(cat) in=$(echo "$in" | perl -pe 's/\**//smig') # for proc subst # Return prepped string echo -e "preped for logging: '$in'" } 2log() { local in=$(cat) if [ "$in" != '' ]; then echo -e "$in" | logprep >>"$logfile" # out to logfile fi return 0 } 2log2scr() { local in=$(cat) # 2scr if [ "'$in'" != '' ]; then echo -e "$in"; fi # 2log if [ "$in" != '' ]; then echo -e "$in" > >(logprep >>"$logfile") # out to logfile fi return 0 } runner () { echo -e "started running\n" "${@}" 1> >(2log) 2> >(2log2scr | tee >&2) # <<< RUNNER #while [ -e /proc/15435 ]; do sleep 0.1; done # <<< HERE echo -e "finished running\n" } success() { eval 'version=$(echo "SUCCESS: **** ${BASH_VERSION} ****")' echo -e "$version"; return 0 } failure() { eval 'version=$(echo "FAILURE: **** ${BASH_VERSION} ****")' echo -e "$version" 1>&2; return 64 } runner success # to test a successful command runner failure # to test a command that errs echo "EVAL IS: $version"