5
import java.io.*;
class Sysexecute
{
public static void main(String args[]) throws IOException,InterruptedException,IllegalThreadStateException
{
Runtime rt= Runtime.getRuntime();
Process p=rt.exec("ls");
System.out.println(p.exitValue());
}
}
我正在學習如何在java中執行系統命令併發生此錯誤。我試圖用拋出否定它,但沒用。請解釋原因和解決辦法處理IllegalThreadStateException
actual error:-
Exception in thread "main" java.lang.IllegalThreadStateException: process hasn't exited
at java.lang.UNIXProcess.exitValue(UNIXProcess.java:270)
at Sysexecute.main(Sysexecute.java:8)