How to execute a batch file from java?

前端 未结 7 485
逝去的感伤
逝去的感伤 2020-12-09 20:42

I want to execute a batch file from a java program.

I am using the following command.

Runtime.getRuntime().exec(\"server.bat\");

Bu

7条回答
  •  暖寄归人
    2020-12-09 20:56

    The second parameter to exec is a String[] of args for the environment settings (null means inherit the process' current ones) and the third parameter to exec should be a file providing the working directory. Try this:

    Runtime.getRuntime().exec("cmd /c server.bat", null, new File("./com/project/util"));
    

提交回复
热议问题