【发布时间】:2016-10-31 07:42:22
【问题描述】:
我正在尝试从 command.com not cmd.exe 读取输出,因此我尝试使用以下代码:
Process p=Runtime.getRuntime().exec("command /c echo goodbye world"); //command.com doesn't work eiher
p.waitFor();
BufferedReader reader=new BufferedReader(
new InputStreamReader(p.getInputStream())
);
String line="";
String output="";
while((line = reader.readLine()) != null)
{
output+=line;
}
System.out.print(line);
不幸的是,它不打印任何东西,但是当我用 cmd 完美替换命令时它可以工作。 我试过 ro 在 cmd 中运行 'command /c echo goodbye world' ,它可以工作。 我已经在 windows me 和 XP 中尝试过这段代码,因为 command.com 在新的 windows 版本中不存在。
【问题讨论】: