We help IT Professionals succeed at work.

How to pass a return code from a Java app to a calling Unix shell script

West100
West100 asked
on
What would be the best way to pass a return code from a Java app back to a calling Unix korn shell script?

I have a small basic Java app that reads a flat file, processes the file then writes good and bad output files.  In the Java app I am catching IOExceptions and logging them.  

If a file is not found I am catching that error but I also need to pass to the calling shell script a return code that indicates that the Java app finished processing with an exception.   How should I pass a negative/exception generated return code back to the shell script? Currently the return code the Unix script (if [ $rcode -ne 0 ]) is getting is 0 regardless if there is an IOException or not.

Thanks
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Awarded 2011
Awarded 2011

Commented:
System.exit(code) should return the code back to Unix
CERTIFIED EXPERT
Top Expert 2016
Commented:
And from the app

System.exit(exitValue);
Awarded 2011
Awarded 2011
Commented:
You should close your java applictaon with System.exit(1) if it is not running correctly and System.exit(0) wif it siis OK.
You don't need any Process for that
CERTIFIED EXPERT
Top Expert 2016

Commented:
From Java to Unix would be System.exit
Awarded 2011
Awarded 2011
Commented:
Sure, so it is strange what you accepted.
Awarded 2011
Awarded 2011

Commented:
Thanks, CEHJ
I very much appreciate it.
CERTIFIED EXPERT
Top Expert 2016

Commented:
np :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.