我想用java程序运行命令,但是p.waitfor()函数会一直等待。代码有什么问题?p.waitfor()永远等待
import java.io.*;
public class doscmd
{
public static void main(String args[]) throws InterruptedException
{
try
{
Process p=Runtime.getRuntime().exec("cmd /c dir");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
System.out.println("Done");
}
}
该程序似乎没有'waitFor()'工作正常。你为什么需要它? – 2012-02-01 20:03:54