Search code examples
javaprocessbuilder

Close CMD window that have been opened through “/c start /wait” in Java


Is there a way to close CMD windows that have been opened through "/c start /wait" in Java? I use ProcessBuilder to launch a process in a new CMD window to see what is going on in that application:

ProcessBuilder pb = new ProcessBuilder("cmd", cmdString);
Process p = pb.start();

Is there a way to shot down / close applications that have been started this way?

ALTERNATIVELY: Is there a way to open a command line application in a new window without going too fancy?

Thanks a lot in advance.


Solution

  • Get rid of the START and /WAIT, and use Process.destroy() to destroy the CMD.