How to execute a batch file from java?

前端 未结 7 482
逝去的感伤
逝去的感伤 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 21:05

    You have to run "cmd.exe" with the arguments "/c" and "server.bat":

    Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "server.bat" } );
    

提交回复
热议问题