| Author |
Returning error code from jar application
|
Makesh Kumar Ramakrishnan
Ranch Hand
Joined: Jan 07, 2006
Posts: 88
|
|
I am not sure, you came across the similar situation or there is a solution for this problem. I need to return an error code from my jar application to the calling application. This jar application does some core java functionality and if it finds any unusal situation while executing the code, then it returns with the error code to the calling function. The calling function may be a unix shell script. Can I use System.exit(n) to return the error code? Can this return value be received by the calling function? Please let me know your answers Thanks, Makesh
|
Makesh<br /> <br />SCJP | SCWCD | SCBCD | SCEA
|
 |
Chandra Sagi
Ranch Hand
Joined: May 05, 2005
Posts: 162
|
|
Normally System.exit(0) kills the JVM, so it may not return you any values. Thanks Chandu
|
 |
Makesh Kumar Ramakrishnan
Ranch Hand
Joined: Jan 07, 2006
Posts: 88
|
|
|
My understanding is, System.exit(0) is a normal exit of JVM. and System.exit(1) is forced shutdown of JVM.
|
 |
Chetan Parekh
Ranch Hand
Joined: Sep 16, 2004
Posts: 3636
|
|
Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. API [ February 27, 2006: Message edited by: Chetan Parekh ]
|
My blood is tested +ve for Java.
|
 |
Makesh Kumar Ramakrishnan
Ranch Hand
Joined: Jan 07, 2006
Posts: 88
|
|
|
Can this returned status code be properly received by the calling application?
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Makesh Kumar Ramakrishnan: Can this returned status code be properly received by the calling application?
Yes, it can. That is in fact the only purpose of the parameter - to serve as an error code returned to the caller. It probably would have been faster and easier to simply try this, wouldn't it?
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Makesh Kumar Ramakrishnan: My understanding is, System.exit(0) is a normal exit of JVM. and System.exit(1) is forced shutdown of JVM.
No, the JVM exits in the same way, regardless of the error code. The code simply is passed to the operating system, which passes it to the caller (if the OS supports it).
|
 |
Chetan Parekh
Ranch Hand
Joined: Sep 16, 2004
Posts: 3636
|
|
|
Hey Ilja Preuss, what System.exit(-1) do?
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Chetan Parekh: Hey Ilja Preuss, what System.exit(-1) do?
The same as System.exit(42) or System.exit with any other value, just with a different exit code, of course. Why do you ask? Did you expect it to do something special?
|
 |
Chetan Parekh
Ranch Hand
Joined: Sep 16, 2004
Posts: 3636
|
|
Originally posted by Ilja Preuss: The same as System.exit(42) or System.exit with any other value, just with a different exit code, of course. Why do you ask? Did you expect it to do something special?
Hey Ilja , you are right. I had a conception that when you use System.exit(-1), than only JVM will killed. I checked here and regardless of the values I pass, System.exit() kills the JVM. Thnaks
|
 |
 |
|
|
subject: Returning error code from jar application
|
|
|