In java determine if a process created using Runtime environment has finished execution?

后端 未结 4 1203
一整个雨季
一整个雨季 2021-01-13 11:08
Runtime.getRuntime.exex(\"abc.exe -parameters\");

using .waitFor() does not help to determine the completion of process.

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 11:15

    I have a similar issue and neither of the methods written here works for me. This is my code:

    public void startCCleaner() {
        System.out.println("Starting ccleaner...");
        try {
            Process process = new ProcessBuilder("C:\\Program Files\\CCleaner\\CCleaner64.exe").start();
            if(process.waitFor() == 0 ){
                System.out.println("Process terminated ");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题