0

I'm trying to run a Java program that runs the tskill Windows command, but im getting the exception listed in the title. tskill is on the path when I run it from the command prompt. I'm running this program as a Java Application in Eclipse. I added c:\windows\system32 to the Path in eclipse, but the java program still can't find it. How do I fix this? How can I determine what path is set to in the java program?

    try {
        RunProcess.doExecuteCommand("tskill winword /A");
        Thread.sleep(1000);
    } catch (Throwable t) {
        throw new GenerationException(t);
    }
}
Mr Smith
  • 3,318
  • 9
  • 47
  • 85

1 Answers1

1

Try this

try {
    Runtime rt = Runtime.getRuntime();
    rt.exec("tskill winword /A");
} catch (Throwable t) {
    t.printStackTrace();
}
VinhNT
  • 1,091
  • 8
  • 13
  • I checked, under the hood, that is what RunProcess.doExecuteCommand is doing. How can I determine the path that Runtime.getRuntime() is looking in? – Mr Smith Mar 30 '16 at 18:20
  • What is the full package of RunProcess? Seem that is not standard class of JDK? – VinhNT Mar 31 '16 at 02:14
  • Runtime.getRuntime return the environment that your Java application is running, it contains all environment enheritance from OS if you do not overwrite it by setting in eclipse or extra parameter while running application – VinhNT Mar 31 '16 at 02:17