Java: wait for exec process till it exits

前端 未结 3 1173
傲寒
傲寒 2020-12-31 13:19

I am running a java program in Windows that collects log from Windows events. A .csv file is created on which certain operations are to be performed.

The commands a

3条回答
  •  没有蜡笔的小新
    2020-12-31 13:57

    I found the answer here Run shell script from Java Synchronously

    public static void executeScript(String script) {
        try {
            ProcessBuilder pb = new ProcessBuilder(script);
            Process p = pb.start(); // Start the process.
            p.waitFor(); // Wait for the process to finish.
            System.out.println("Script executed successfully");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题