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中执行系统命令,但是出现了这个错误。我尝试使用throws来解决它,但没有用。请解释原因并提供解决方案。
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)