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

后端 未结 4 1196
一整个雨季
一整个雨季 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:37

    If you don't want to use waitFor(), which apparently you don't you can always test the exit value directly.

    import java.util.*;
    import java.io.*;
    public class ProcExitTest
    {
        public static void main(String args[])
        {
            try
            {            
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("<....>");
                int exitVal = proc.exitValue();
                System.out.println("Process exitValue: " + exitVal);
            } 
              catch (InterruptedException ie)
              {
                ie.printStackTrace();
              }
        }
    }
    

    exit code 0 means normal termination.

提交回复
热议问题