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);
}
}
}
{ 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);
}
}
}
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;
}
}
waitFor()执行完了,你调用的程序也就执行完了。
{ System.out.print("error "+e);
}finally{
......
}
在程序的finally 里面做判断,当执行到finally 时,程序即将执行完毕。当执行到finally的最后一条时,程序返回,执行完毕。