我想用java命令运行批处理文件。 我有以下代码在java中执行带有args的批处理文件
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窗口。
你能帮我实现吗? 在此先感谢
您只传递3个参数为什么使用'%4','%5'和'%6'? – talex
1)“cmd.exe”, 2)“/ c”, 3)“start C:\\ temp \\ Sept_2016 \\ 22Sept \\ filecompare.bat”, 4) )file1, 5)file2, 6)file3 – Sachin
我相信你的String []的前三个元素应该连接在一起。顺便说一句,为什么你不能串联所有的字符串,只传递一个字符串? – freefall