我正在寻找java代码的帮助。我想从java代码开始运行.bat 有人可以帮助我,提前谢谢:)
答案 0 :(得分:1)
Runtime.getRuntime().exec("cmd /c start build.bat");
答案 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链接:)