I have written an application in Java. Then, I packed it into a JAR file and now I run it from command line using "java -jar myapp.jar". Because it connects to the web, sometimes it throws the IOException. So what I'd like to do is to check JAR file's return value on application finish (when application closes gracefully it returns 0 and when it closes because of an exception it returns 1). Next, I'd like to run this JAR file as long as it won't return the 0 value (some kind of while loop). Thanks for help.
You can ask for the exit value of a process in bash by using
$?
. This variable contain the exit value of the last process executed (0
or1
in your case).So to run your script as intended you can use something like