Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing java's status code to c++

Status
Not open for further replies.

vkarthik

Programmer
Aug 30, 2001
126
US
I have a c++ wrapper over a java application, and c++ uses the jni library to launch a jvm, and invoke the main method of the application. I have a requirement that, when the java application exits, it has to pass the 'status code' to the wrapper somehow. By status code, I mean, "return 0" or "return 1" or something like that which we do in C's main function. But as the main method is void return type, I don't know how to handle this. Can someone help?

LOL A ship is safe in the harbour, but that's not what it is meant for!!! LOL
 
Somewhere in your program, perhaps in the finalize method of the main class, you can put a System.exit(0) or System.exit(1) call. This terminates the app immediately and returns the status value from your application (0 and 1 are examples - I think it's an int).

Whether the status code gets passed from the jvm to your wrapper is another question. Let us know if it works.
 
Hey thanks! I did think of this, but my concern was, how should the wrapper receive it.

To make my requirement clear, my java app runs as a win2k service. That is, there is a c++ wrapper that implements "windows service manager" api, and also runs this java program (using jni).

And you know this "Event Viewer" in Windows, that is present in Control Panel > Administrative Tools > Event Viewer. This program gives the status of the events, whether the applications exited normally or abnormally etc. I'm supposed to change my code so that, when my java app exits, the event viewer should get the message, and display the "normal" or "abnormal" status. If my app had been a normal c / C++ program, I would've returned 0 or 1 in main method, and that'd've done the work automatically (that is, windows wouldve got the message and informed event manager about it). I donno how to do this now, as it is my java code that has to decide exit(1) or exit(0).



LOL A ship is safe in the harbour, but that's not what it is meant for!!! LOL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top