[one-users] exec_and_log doesn't propagate exit status

Sander Klous sander at nikhef.nl
Mon Aug 24 13:28:05 PDT 2009


Hi Javier,
Can you include this change upstream?
Or does it violate one of your programming conventions?
Thanks,
Sander

Javier Fontan schreef:
> Hello,
>
> On Mon, Aug 24, 2009 at 4:59 PM, Sander Klous<sander at nikhef.nl> wrote:
>   
>> Hi,
>> I think exec_and_log doesn't propagate the exit status of the command it
>> executes. Is that true?
>> So, if I do:
>>
>> exec_and_log "ls bla"
>> echo $?
>>
>> I would like to see the exit status of `ls bla`.
>> At the moment, I think it just returns -1 on failure.
>> Is that right?
>>     
>
> You are right, when the command fails it always returns -1 (from tm_common.sh):
>
> --8<------
> # Executes a command, if it fails return error message and exits
> function exec_and_log
> {
>     output=`$1 2>&1 1>/dev/null`
>     if [ "x$?" != "x0" ]; then
>         log_error "Command \"$1\" failed."
>         log_error "$output"
>         error_message "$output"
>         exit -1
>     fi
>     log "Executed \"$1\"."
> }
> ------>8--
>
> I think you can modify it to return the command exit code this way:
>
> --8<------
> # Executes a command, if it fails return error message and exits
> function exec_and_log
> {
>     output=`$1 2>&1 1>/dev/null`
>     code=$?
>     if [ "x$code" != "x0" ]; then
>         log_error "Command \"$1\" failed."
>         log_error "$output"
>         error_message "$output"
>         exit $code
>     fi
>     log "Executed \"$1\"."
> }
> ------>8--
>
> Bye
>
>   




More information about the Users mailing list