我使用运行时运行命令提示符命令从我的java程序。然而我不知道如何我可以得到命令返回的输出。
这里是我的代码。
Runtime rt = Runtime.getRuntime();
String[] commands = {"system.exe","-send",argument};
Process proc = rt.exec(commands);
我试过做system.out.print(proc);但是没有返回任何东西。该命令的执行应该返回两个用分号分隔的数字,我怎么能得到这个在一个变量打印出来?
谢谢,
这里是我现在使用的代码:
String[] commands = {"system.exe","-get t"};
Process proc = rt.exec(commands);
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
但我没有得到任何东西作为我的输出,但当我自己运行这个命令,它工作正常。