using Runtime.exec() in Java

前端 未结 4 985
生来不讨喜
生来不讨喜 2020-12-03 20:06

What do you have to do in Java to get the Runtime.exec() to run a program that is on the path? I\'m trying to run gpsbabel which I have put into the path (/usr/local/bin).

4条回答
  •  感动是毒
    2020-12-03 20:24

    Here is the solution:

    ProcessBuilder proc = new ProcessBuilder("" + "Executable.exe");
    proc.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    proc.directory(fi); //fi = the output directory path
    proc.start();
    

    is the path where program\application's excutable is located e.g "C:\MyProg\"

提交回复
热议问题