I have a java program which throws some exception,I tried executing it from shell script and printing 0 on failure and 1 on successful execution of java program.But It also printing the Exception onto console I just want to print exit code only.How to do this ?.Any suggestion are appreciated .
following are my Java program and script files Test.Java
public class EchoTest {
public static void main (String args[]) {
System.out.println ("scuccess Prasad Bezavada "+(2/0));
}
}
Test.sh(script file)
java Test
if [ $? -eq 0 ]
then echo "1"
else echo "0"
fi
getting the following out put
$sh Test.sh
Exception in thread "main" java.lang.ArithmeticException: / by zero
at EchoTest.main(EchoTest.java:3)
0
$
Expecting output is like below(i.e just want to skip the exception message)
$sh Test.sh 0 $