从java类启动.bat文件:

时间:2015-04-10 08:49:12

标签: java batch-file

我正在寻找java代码的帮助。我想从java代码开始运行.bat 有人可以帮助我,提前谢谢:)

4 个答案:

答案 0 :(得分:1)

Runtime.getRuntime().exec("cmd /c start build.bat");

请参阅:How do I run a batch file from my Java Application?

答案 1 :(得分:1)

Runtime.getRuntime().exec("cmd /c start yourbatchfile.bat");

答案 2 :(得分:0)

添加以下代码行,它将运行bat batFile.bat

Runtime.getRuntime().exec("cmd /c start batFile.bat");

答案 3 :(得分:0)

我总是这样做:

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

或者使用Java中的ProcessBuilder类:http://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html

File batchFile = new File("build.bat"); //Or wherever your file is
ProcessBuilder processBuilder = new ProcessBuilder(batchFile.getAbsolutePath());
Process process = processBuilder.start();

有关更多信息,请查看JavaDoc链接:)