我正在尝试使用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窗口。
你能帮我实现这一点吗?提前感谢
发布于 2016-09-23 21:01:25
用fc %1 %2>>%3替换fc %4 %5>>%6。
在执行filecompare.bat时,只知道它自己的参数,而不知道传递给cmd的参数。
https://stackoverflow.com/questions/39661236
复制相似问题