Skip to main content

How I can get the return code or exit code of a JAR program

2 replies [Last post]
davor
Offline
Joined: 2006-05-05
Points: 0

Hi,

How I can get de return code when I run a JAR program? and

How I can return a code or exit code in a java programa?

For example:

The name of the program is: getNumberFive.jar

I want that the program return a code 5 when I execute on the command prompt:

C:\Users\User1> java -jar getNumberFive.jar

Help!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ptomask
Offline
Joined: 2011-10-23
Points: 0

Hi !

In your application call:

System.exit(5)

you can change 5 to code you need. After jvm terminates, the system saves the error code to the special variable called errorlevel. So in commandline:

C:\Users\User1> java -jar getNumberFive.jar

C:\Users\User1> echo %errorlevel%
5

Hope this helped you,

best regards,

Paul

davor
Offline
Joined: 2006-05-05
Points: 0

Hi Paul,

Thanks for your help.

Your help has helped me in what I need.
Regards,
David.