5

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
5
  • 2
    Please add more of your bash wrapper code, especially what COMMAND_TO_RUN is. I suspect the reason for this in there. Commented Nov 30, 2012 at 23:35
  • 8
    Process exit codes are often truncated to 8 bits, so you're probably not going to get 666 via $? regardless. You might get 154 or -102 depending on your platform. Commented Nov 30, 2012 at 23:47
  • Also, do you have a SecurityManager installed? Commented Nov 30, 2012 at 23:49
  • I get 154 on OS X and on Ubuntu Linux Commented Dec 1, 2012 at 0:21
  • added command_to_run as requested. I think i see where this is going.. was it wrong of me to use the tee and the redirection to log? Commented Dec 1, 2012 at 0:44

2 Answers 2

6

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Nice! I didn't know that $PIPESTATUS existed
very neat! but still (cat nonexistantFile | echo) ; echo "e: $? p: ${PIPESTATUS[@]}" doesn't work - because of the parentheses thing, which is a trick I don't want to give up on (from here: unix.com/shell-programming-scripting/…)
-2

This is because $? is almost certainly giving you the return code of eval, which is succeeding here. Why are you including the eval call in there? Just call the COMMAND_TO_RUN

1 Comment

eval reports as its exit code the result of the process that it spawned. From unix.stackexchange.com/a/23116 : "This command is then read and executed by the shell, and its exit status is returned as the value of eval."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.