• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing java's status code to c++  RSS feed

 
Karthik Veeramani
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a requirement that you have to do something with a value that doesn't exist? Well, as I see it, you've got a few options: you could make a value up (for example, always return 0); you could define and document a value (0 for normal return, -1 for RuntimeException, -2 for error, for example); or, and I know this is a crazy idea, you could talk to the customer about the requirement!
If you, as a developer, get a meaningless requirement, the only professional course of action is to try to get the requirement clarified.
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are looking for the method:
System.exit(<int value here> ;
The reason that main doesn't return anything is because the main exiting doesn't mean that the program is over. It could have launched other non-daemon threads that would continue execution.
Calling System.exit(int) will end all threads and send the exit code given back to the calling process.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!