Destroying spawned ant process, from windows, does not work. Unix variants this works fine but from windows this does not work. Code snippet is below. While the return code is correct (1) the spawned process continues to execute until done. Only a problem on a windows. Any ideas?
ProcessBuilder build = new ProcessBuilder();
List<String> list = build.command();
list.add("cmd");
list.add("/C");
list.add("ant");
list.add("-f");
list.add("HelloWorld.xml");
try {
Process p = build.start();
Thread.sleep(5000);
p.destroy();
int i = p.waitFor();
System.out.println(i);
} catch (Exception e) {
System.out.println(e);
}
The problem is that Process.destroy doesn't kill the process grandchildren. There is a bug opened for it since 2002.
Anyway, why are you spawning a new prompt with cmd /c start to call Ant? If that is not a requirement just call ant.bat -f HelloWorld.xml.
UPDATE
ant.bat will also spawn children processes. There is a workaround with taskkill that may help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With