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
:
((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
The last program called is tee
, which will exit with status 0
, overriding the exit
value of java
.
You can use $PIPESTATUS
, which is an array of return values in the pipe.
For example:
$ cat nonexistantFile | echo ; echo "e: $? p: ${PIPESTATUS[@]}"
Expected output:
e: 0 p: 1 0
cat
will fail (exit code 1), echo will succeed (exit code 0). $?
will be 0
.
${PIPESTATUS[0]}
will contain the exit code for cat
(1
) and ${PIPESTATUS[1]}
the one for echo (0
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With