我需要从eclipse运行以下命令..并在eclipse控制台上打印结果(我比较2个文件)
“fc / c / 1 / n file1path file2path”。 这是我的代码
final Process p = Runtime.getRuntime().exec("cmd /c fc /c/1 /n file1path file2path");
new Thread(new Runnable() {
public void run() {
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line =new String();
try {
line = input.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
while (line != null) {
System.out.println(line);
line = input.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
p.waitFor();
但它没有打印任何东西。代码出了什么问题?
答案 0 :(得分:0)
该计划很好,适合我。问题出在你的命令中。更改您的命令并删除cmd
和额外/c
标志。同时删除无效标记/c/1
。您的最终命令应如下所示: -
final Process p = Runtime.getRuntime().exec("fc /c /n file1path file2path");