• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing java's status code to c++

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic