This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.
=================================================== 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.