struggling with this for an hour... java code:
ULogger.info("throwing out 666!");
System.exit(666);
bash wrapper:
eval ${COMMAND_TO_RUN}
ret_code=$?
printf "error code : [%d]" ${ret_code}
output:
[2012-11-30 15:20:12,971][INFO ] throwing out 666!
error code : [0]
what's the deal here? Thanks...
[EDIT]
The ${COMMAND_TO_RUN}
is
((java -Xmx9000m -Dtoday_nix=20121128 -cp "/usr/lib/hadoop/conf" com.paypal.risk.ars.linking.task_fw.BaseRunnableProcess 3>&1 1>&2 2>&3) | tee /dev/tty) > batches_errors.log
Your problem is in your
COMMAND_TO_RUN
:The last program called is
tee
, which will exit with status0
, overriding the exit value ofjava
.You can use
$PIPESTATUS
, which is an array of return values in the pipe.For example:
Expected output:
cat
will fail (exit code 1), echo will succeed (exit code 0).$?
will be0
.${PIPESTATUS[0]}
will contain the exit code forcat
(1
) and${PIPESTATUS[1]}
the one for echo (0
).This is because $? is almost certainly giving you the return code of
eval
, which is succeeding here. Why are you including theeval
call in there? Just call theCOMMAND_TO_RUN