繁体   English   中英

调用批处理文件Java程序

[英]Calling Batch file Java program

我正在尝试从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()帮助我解决了这个问题。 最初,该块不等待该过程完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM