I hava a simple Java application which uses the ProcessBuilder
and Process
classes to execute cmd commands. The commands just load a window. Now the problem is when the window is closed, the process remains running. Below is the code snippet I have used:
try {
ProcessBuilder pb = new ProcessBuilder(commands);//command to load a gui app
Process process = pb.start();
process.waitFor();
}
catch (IOException ioEx) {
ioEx.printStackTrace();
}
catch (InterruptedException iEx) {
iEx.printStackTrace();
}
How do I make the process to stop when the window is closed?