Home Ask Login Register

Developers Planet

Your answer is one click away!

elder elder February 2016

JVM on OS X always exiting with status 0 (as captured in Bash script)?

I have a very simple Java class, that does nothing else but:

public class TestMain {
  public static void main(String[] args) {

, packed into a TestOSX.jar file.

While on Windows I can run the above snippet and show that %ERRORLEVEL% has the expected value, I get a different outcome on OS X.

Given test.sh containing:


"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" -jar TestOSX.jar 
wait $!
echo $updater_evit_val

, I always print 0.

Setup: OS X 10.11.1, Oracle Java 8 u60.

What trivial detail am I missing here?


visit1985 February 2016

You do not send your java process to the background with &. Thus wait is executed after the java process exits. It can't find the process you try to wait for, because it already exited and giving return code 0 because of that. $? returns the return code of the last command (in your case wait).

You can either remove wait from your script, or you send your java process to the background by adding & at the end.

Post Status

Asked in February 2016
Viewed 1,983 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life