integer value returned from java becomes different value in shell script

153 views Asked by At

Our java program returns a status code at exit by doing

System.out.println(statusCode);

System.exit (statuscode);

The value goes back to the shell script (korn shell) where calls the java class. In the script it gets the return value by storing in a variable RETSTATUS as below -

$JAVA_HOME/bin java $SYSTEM_PARAMS -jar myclass.jar

RETSTATUS=$?

echo $RETSTATUS

Somehow the value printed in java is 400 (correct status code), but the value of RETSTATUS in script is 144 in echo. Any idea why and how to fix it? Thanks for any help in advance.

1

There are 1 answers

1
Mureinik On

Exit codes in *nix are shorts. When you return 400 you overflow the return code (note that 400-256=144). Just return a sensible positive number of 255 and below and you should be fine.