I decided to write a restart Tomcat'a. But here's the problem, after calling shutdown.bat and startup.bat consoles through which I called them do not close

 Runtime.getRuntime().exec("cmd /c start "+tomcatPath+"\\bin\\shutdown.bat"); Runtime.getRuntime().exec("cmd /c start "+tomcatPath+"\\bin\\startup.bat"); 

Tell me please, maybe there is some way to close them, otherwise it’s not very manual to do it.

  • Add exit at the end of each command. - Andrew Bystrov

1 answer 1

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") .

  1. The first cmd /c is launched in the shutdown mode immediately after the execution of the command given to it
  2. It launches a new, second cmd in a new window, but in the continuation mode after executing the command
  3. The latter executes shutdown.bat, which calls call catalina.bat in the same interpreter.
  4. 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.
  5. catalina.bat , without waiting for the java-application to terminate, continues execution. But there are no other commands, so control returns to shutdown.bat
  6. shutdown.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();