好的,所以我一直在尝试Process
andRuntime
类,但遇到了问题。当我尝试执行此命令时 : cmd /c dir
,输出为空。这是我的代码片段:
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c dir");
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
//BufferedReader serverOutputError = new BufferedReader(new InputStreamReader(serverStart.getErrorStream()));
String line = null;
while ((output.readLine()) != null) {
System.out.println(line);
}
int exitValue = process.waitFor();
System.out.println("Command exited with exit value: " + exitValue);
process.destroy();
System.out.println("destroyed");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
我得到这个作为输出:
(18 lines of just "null")
Command exited with exit value: 0
destroyed
有任何想法吗?