2

I am invoking a java program from a shell script "TC Shell Script" and the java program returns status codes which represent certain conditions.

The return code of the java prgram is captured in the pre-defined status variable of the TC Shell.

The return codes are captured fine.

The problem I'm facing is when the java program returns or terminates with -1 with System.exit(-1) the shell script is getting 255 as the return code.

All positive numbers are captured fine in the shell script only -1 is being read as 255.

How can i solve this.

gautam vegeta
  • 653
  • 6
  • 13
  • 28
  • 1
    Sounds like a byte value has wrapped. – Bohemian Aug 03 '12 at 03:26
  • http://stackoverflow.com/questions/2726447/why-is-the-exit-code-255-instead-of-1-in-perl – Jayan Aug 03 '12 at 05:02
  • I guess you mean `tcsh`? This is commonly referred to as the Tenex C shell or simply as `tcsh`. There is a broad movement away from the C shell family; perhaps you should switch to Bash or Zsh (though for this question, it doesn't matter really). – tripleee Aug 20 '15 at 07:29

1 Answers1

3

Return codes from executables are a small positive number. Negative numbers get converted to unsigned. There is no way to get a negative number into the exit code.

tripleee
  • 175,061
  • 34
  • 275
  • 318