public class HWLoop
{ public static void main(String[] args)
  { try
    {
     Process proc = Runtime.getRuntime().exec("D:\\process.exe");
     proc.waitFor();
    }
    catch(Exception e)
    { System.out.print("error "+e);
    }
  }
}

解决方案 »

  1.   


    import  java.io.*;  
     
    public  class  HWLoop    
         {  
             public  static  void  main(String  args[])  
                 {  
                   Process p = null;
                   try{  
                         p =Runtime.getRuntime().exec("D:\\process.exe");    
                         //p.waitFor();
                         System.out.println(p.exitValue());
                         }  
                   catch(Exception  e){  
                         System.err.println(  "Program has not exited.");  
                         try{
                          p.waitFor();
                         }catch(InterruptedException ee){
                         
                         }
                         System.err.println(  "Program has exited.");
                   }          
         
                   //return;    
                 }  
         }
      

  2.   

    直接判断p.waitFor()的返回值就可以了,0就是正常退出。
    waitFor()执行完了,你调用的程序也就执行完了。
      

  3.   

    catch(Exception e)
        { System.out.print("error "+e);
        }finally{
    ......
    }
    在程序的finally 里面做判断,当执行到finally 时,程序即将执行完毕。当执行到finally的最后一条时,程序返回,执行完毕。