sgtFloyd
sgtFloyd

Reputation: 1007

Setting default System.exit codes in Java?

I have a C# app that runs a jar file and uses the System.exit code as a return value. A console window is displayed as a part of this jar, and if the user closes it (thereby terminating the jar) it returns an exit code of 143. The problem is that 143 (or any positive integer) could be a valid exit code if the jar completes successfully.

I need a way to manually set the System.exit code to a negative integer. Treating 143 as an exception in the C# app is out of the question.

Upvotes: 2

Views: 6065

Answers (2)

Peter Lang
Peter Lang

Reputation: 55524

As in Diego Dias answer,

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

If you really want to ignore that, and both the Java and the C# apps are in your hand, an easy workaround is to add 1000 to your System.exit return value in Java, when the jar completes.

Your C# application will recognize the successful execution by a return code >= 1000 and subtract it again. 143 is below 1000 and thus an error.

Upvotes: 2

Diego Dias
Diego Dias

Reputation: 22606

Acording to the java documentation you can use System.exit(int n), so just put a negative number as a parameter, also by convention, a nonzero status code indicates abnormal termination.

Upvotes: 1

Related Questions