How to capture return value from java in shell scripting

Hi All,

My shell script will call a java component with some arguments , the java component returns a string value to the shell script. How to assign the return value to the shell variable.

Here is the sample code.

In my shell script i am calling the java as fallows.

--exporting classpaths and relevant jar files

java com.sample.Demo arg1 arg2

Demo.java

has return value "myReturnValue"

How to handle this return value in the shell scripting.

Please help me it is argent.

Note Java takes arguments.

if it does not takes arguments below code is fine

ret_value=`java com.sample.Demo`
echo "$ret_value"

If running:

ret_value=`java com.sample.Demo arg1 arg2`

Does not work then you could get the java script to save its output to a temporary file and then get the shell script to read in the contents of the file:

VARIABLE=`cat /tmp/temporary_file`