java 运行cmd命令 等待执行bat

时间:2022-09-03 16:30:31

java执行bat 文件等待执行完bat命令 阻塞 加个 wait就行 貌似

public class Command {

public static void main(String[] args) throws java.io.IOException, InterruptedException {
String path = "C:\\Users\\andreas";

Process p = Runtime.getRuntime().exec("cmd /c start /wait " + path + "\\RunFromCode.bat");

System.out.println("Waiting for batch file ...");
p.waitFor();
System.out.println("Batch file done.");
}
}