我正在尝试从 Java 函数调用 bat 文件。看起来我调用 bat 文件的方式有问题。该方法不会调用批处理文件。任何帮助将不胜感激。
private static void Run_Main() throws InterruptedException, SQLException, IOException {
int set_value=0;
while ((set_value=Find_Flag()) !=0){
System.out.println("Set_Value"+set_value);
System.out.println("Staging load is not completed ..Revisiting after 15 minutes....");
Thread.sleep(900000);
set_value=Find_Flag();
}
System.out.println("Staging load is Completed and launching Proudction Load now");
//Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "C:/exec/DW_Init_Load.bat" } );
String filePath = "C:/exec/DW_Init_Load.bat";
try {
Process p = Runtime.getRuntime().exec(filePath);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Production Load is finished");
}
我有兴趣知道我在代码中犯了什么错误
最佳答案
添加 p.waitFor() 帮助我解决了这个问题。最初,该 block 不会等待该过程完成。
关于java - 调用批处理文件Java程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34516141/