• 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

Return value from main

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am executing java application from shell script. I want to return some value from application which will be used as status code by shell script.
How we should be able to do it?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use System.exit(returncode) to end the application (see the API documentation).
[ September 06, 2005: Message edited by: Jesper de Jong ]
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jesper de Jong:
Use System.exit(returncode) to end the application (see the API documentation).

[ September 06, 2005: Message edited by: Jesper de Jong ]



Using System.exit(n) is probably the best way to return an error code, in a simple Java application.

However, in a complicated system, it is less than ideal. System.exit() kills the whole Java process. It does not wait for non-daemon threads to finish, so important tasks might get terminated at a bad time.

Further, if your code might get incorporated into some larger overall application framework, then System.exit() is a bit of a disaster because it will terminate the whole application framework, not just your code.

Using the standard Java launcher (e.g. java.exe on Windows), there is no way to control the process exit code, except System.exit(). However, if you write or obtain a different launcher, alternative facilities may be added. For example, I have a launcher with a native method setExitCode(), through which I can set the code that the Java process will use, when it finally exits. Writing launchers Google for "Java Invocation Interface".
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajendra,

I think 1 option is to store the return code in a file and retrieve that in the shell script
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic