0

Im trying to kill a process from my JAVA code:

    File file = new File("c://test//test.jar");
    String folderToFile = file.getAbsolutePath();
    String filePath = folderToFile.substring(0,folderToFile.lastIndexOf(File.separator));
    String[] cmd = String.format("cmd /c java -jar %s", file.getName()).split(" ");
    Process pSimulator = (new ProcessBuilder(cmd))
            .directory(new File(filePath))
            .redirectErrorStream(true)
            .start();

    Thread.sleep(300);
    pSimulator.destroy();

I don't know why but the process that i'm trying to kill remains open... the "test.jar" that i'm running here is just a rendom jar that i've picked on the web...

any ideas?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Evgeni
  • 1
  • 1

1 Answers1

0

Looks like it is a bug in Java's Process.destroy() implementation on Windows. Refer this.

You can try to use Apache Commons Exec.

Lii
  • 11,553
  • 8
  • 64
  • 88
v.ladynev
  • 19,275
  • 8
  • 46
  • 67