If you need to use the return value from a Java program in the shell script that called it then this example will show you how.
Java program
public class TestReturn
{
public static boolean doStuff()
{
// your code here
// return true if successful, false otherwise
}
public static void main(String[] args)
{
if(doStuff())
{
// success
System.exit(0);
}
else
{
// failure
System.exit(-1);
}
}
}
{
public static boolean doStuff()
{
// your code here
// return true if successful, false otherwise
}
public static void main(String[] args)
{
if(doStuff())
{
// success
System.exit(0);
}
else
{
// failure
System.exit(-1);
}
}
}
Shell script
#!/bin/sh
java TestReturn
result=$?
echo $result
java TestReturn
result=$?
echo $result
In bash script $? means the result of the previous command. You could also use
#!/bin/sh
result = $(java TestReturn)
echo $result
result = $(java TestReturn)
echo $result