Exitcode of BackGround Job

Hi,

i have the following code, to catch the whole output to log it for
debugging purposes.

> function call_ext_cmd()
> {
> logmsg2 $LOGFILE $DEBUG_FLAG "--- Begin call of $*"
> COMMAND="$*"
> [[ $BIG_DEBUG -eq 1 ]] && {
> file $COMMAND | grep -q 'Bourne-Again shell script' && {
> COMMAND="sh -x $COMMAND"
> }
> }
> FIFO="/tmp/call_ext_cmd.fifo"
> rm -f $FIFO
> mkfifo $FIFO
>
> $COMMAND &> $FIFO &
> while read FIFO_LINE;
> do
> logmsg2 $LOGFILE $DEBUG_FLAG "--- Call of `basename $1`: $FIFO_LINE"
> done < $FIFO
>
> rm -f $FIFO
> logmsg2 $LOGFILE $DEBUG_FLAG "--- End call of `basename $1`"

return EXITCODEOF$COMMAND

> }

I want to catch the exit code of $COMMAND. How can i do this?
How should "return EXITCODEOF$COMMAND" be written?

Thanks a lot

D.Laurenz
Dirk Laurenz [ Di, 17 Januar 2006 11:10 ] [ ID #1144434 ]

Re: Exitcode of BackGround Job

> I want to catch the exit code of $COMMAND. How can i do this?
Hi,
I don't no if there are other ways, I usually do something like this:

($COMMAND &> $FIFO; echo $? > somefile) &

return the result stored in the file

or:
$COMMAND &> $FIFO
pid_of_your_background_process=$!
....
wait $pid_of_your_background_process
returns the exit code of your background process

If you have a lot of background process running together
the first method is maybe more appropriate
Fred [ Di, 17 Januar 2006 18:08 ] [ ID #1144441 ]
Linux » comp.unix.shell » Exitcode of BackGround Job

Vorheriges Thema: What is wrong with this sed script
Nächstes Thema: why quotation mark lost when using $@ to show bash parameters?