The documentation from the java program says:
EXIT STATE
The following output values ββare usually returned at startup, usually when the caller is called with incorrect arguments, serious errors, or exceptions thrown from the Java virtual machine. However, a Java application can select any value using the System.exit (exitValue) API call.
- 0: successful completion.
- > 0: An error has occurred.
So, if you do nothing, the JVM follows the general convention of returning a 0-value to the caller on success and a non-zero value in case of an error.
Your shell script should be as follows:
java EchoTest if [ $? -eq 0] then echo 1 else echo 0 fi
This means that you can ignore standard output and standard error and simply rely on the exit status of the JVM.
As suggested by @alk, you can even replace the first line out = $( java EchoTest ) and use $out in the success branch (when $? Is 0 )
Serge Ballesta
source share