| Author |
Running a .jar application from a unix shell script
|
ram shyam
Ranch Hand
Joined: May 04, 2007
Posts: 77
|
|
Hi all, I have a unix shell script that calls a java application (.jar file). When the jar file is executed, some analysis is done and either 0 or 1 is printed. I want this value to be returned to the shell script instead of printing on the console, say for eg., shell script can be as follows =================================================== echo "Running a sample shellscript"; c=`java -jar sample.jar` < some operation carried out with $c > =================================================== Since the main method in java is void type, value cannot be returned to the calling shell script. How will I retrieve the value from the jar application? Please let me know how can this be achieved. Thanks in advance!!
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14456
|
|
java.lang.System.exit(exitCode); This will immediately terminate the application and return the indicated exit code. So normally you'd make this the last statement in the main() method. To use the exit code, reference the shell variable "$?". [ December 24, 2008: Message edited by: Tim Holloway ]
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
=================================================== echo "Running a sample shellscript"; c=`java -jar sample.jar` < some operation carried out with $c > ===================================================
To run it in that fashion, just put a "System.out.println (value);" in your Javafile, especially useful, if there are different results indicating success possible, because exit-values != 0 normally indicate failure. Instead of , which is discouraged, use because it is better readable, and better cascaded.
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
ram shyam
Ranch Hand
Joined: May 04, 2007
Posts: 77
|
|
Hi, Thanks for your reply!!! It is working for me now.
|
 |
 |
|
|
subject: Running a .jar application from a unix shell script
|
|
|