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()'なしで正常に動作しているようです。なぜあなたはそれが必要なのですか? –