You can try to figure out what happens during the exec("cmd /c start "+tomcatPath+"\\bin\\shutdown.bat") command exec("cmd /c start "+tomcatPath+"\\bin\\shutdown.bat") .
- The first
cmd /c is launched in the shutdown mode immediately after the execution of the command given to it - It launches a new, second
cmd in a new window, but in the continuation mode after executing the command - The latter executes shutdown.bat, which calls
call catalina.bat in the same interpreter. catalina.bat does something like start java org.apache.catalina.startup.Bootstrap stop , i.e. opens a new window in which the java-application is launched.catalina.bat , without waiting for the java-application to terminate, continues execution. But there are no other commands, so control returns to shutdown.batshutdown.bat also ends there, and control returns to the second cmd , which expects the next commands from the user. Here it is, an unclosed window.
What can be done here? For example, change the startup mode of the second command interpreter: "cmd /c start cmd /c "+tomcatPath+"\\bin\\shutdown.bat" In this case, after shutdown.bat , the cmd will also close and the window will disappear.
You can refuse to call the first interpreter:
Runtime.getRuntime().exec(tomcatPath+"\\bin\\shutdown.bat").waitFor(); Runtime.getRuntime().exec(tomcatPath+"\\bin\\startup.bat").waitFor();