[英]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_2016\22Sept\MSP_Files\msp.txt" "C:\temp\Sept_2016\22Sept\MIB_Files\mib.txt">>"C:\temp\Sept_2016\22Sept\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窗口。
你能帮我实现这个吗? 提前致谢
将fc %4 %5>>%6
替换为fc %1 %2>>%3
。
被执行的filecompare.bat
仅知道其自身的参数,而不是您传递给cmd
参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.