使用 java 中的参数执行批处理文件

Execute batch file with args in java

我正在尝试使用 java 命令 运行 批处理文件。 我有以下代码

Runtime.getRuntime().exec("cmd /c start C:\temp\Sept_2016\22Sept\filecompare.bat");

我有一个名为 filecompare.bat 的批处理文件,如下所示

fc "C:\temp\Sept_2016Sept\MSP_Files\msp.txt" "C:\temp\Sept_2016Sept\MIB_Files\mib.txt">>"C:\temp\Sept_2016Sept\mismatch.txt"

这按预期工作,输出存储在 txt 文件中。

现在我不想像上面那样使用硬编码值,我想从 Java 程序中获取值。所以我正在编写 java 代码如下

String file1 = new String("C:\temp\Sept_2016\22Sept\MSP_Files\msp.txt");
String file2 = new String("C:\temp\Sept_2016\22Sept\MIB_Files\mib.txt");
String file3 = new String("C:\temp\Sept_2016\22Sept\mismatch.txt");
Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "start C:\temp\Sept_2016\22Sept\filecompare.bat", file1, file2, file3}); 

在类似的行上,我将批处理文件修改为

fc %4 %5>>%6

但这似乎不起作用。就是打开dos window.

你能帮我实现这个吗? 提前致谢

fc %4 %5>>%6 替换为 fc %1 %2>>%3

filecompare.bat 被执行只知道它自己的参数,而不是你传递给 cmd.

的参数