Java Return Value to Unix Shell Script

Today I faced a situation where I need to verify something though Java class in database . My problem was I have to do this inside unix shell script. I created the below solution to achieve that, I am posting here sample working code:


public class Sample

public static void main(String args[])
//Do the complete logic and print the result using system out
System.out.println(“Sample Testing”);    

Shell Script


#Store the result(printed through system out) of program in variable
result=$(${JAVA_HOME} -cp ${CLASSPATH} Sample)
#Print the result.
echo  “My Results =>” $result

Leave a Reply

Your email address will not be published. Required fields are marked *