My application exits with error code 136 and I want to make sure it does.
For that I'm executing set +e to continue execution and then a condition:
> set +e
> java -jar myjar.jar
> if [ $? -eq 136 ]; then echo success; exit 0; else echo fail; exit 1; fi
This always ends up printing the following output:
fail
Does set +e modifies in any way the exit code? Why is it zero even when I'm exiting with 136?
I've also tried string comparison to no success:
EDIT:
I modified it according to the first answer and comments but the exit code still is not correct:
> java -jar myjar.jar
> EXIT_CODE=$?
> if [ $EXIT_CODE == 136 ]; then echo success; exit 0; else echo fail; exit 1; fi
I tried with different exit codes like 1 or 126 but it doesn't work.
I've also done the following:
> java -jar myjar.jar
> EXIT_CODE=$?
> echo $EXIT_CODE
and the result is 0 (it doesn't matter how I exit from my app)
The exit code in my app is the following:
if (mycondition) {
logger.log(LogLevel.WARN, "Exiting with error code 126");
System.exit(126);
} else {
logger.log(LogLevel.WARN, "Exiting with error code 0");
System.exit(0);
}
and even when mycondition is true, the exit code in the shell is 0