我需要执行带有2个参数的命令行程序。但是,它必须在工作目录中执行。即“command arg1 arg2”,而不是“c:\ folder \ subfolder \ command arg1 arg2”我需要在Java的特定工作目录中执行命令行程序
从这里的其他问题,我已经开始使用Runtime.exec(cmdArray,null,workingDirectory);但我不断收到“CreateProcess错误= 2,系统找不到指定的文件”。我已经检查过了,路径和文件都存在,所以我不知道发生了什么问题。这是我正在使用的代码。
String [] fileName = {"mp3wrap.exe", "Clear_10", "*.mp3"};
String dirName = "E:\\Music\\New Folder\\zz Concatinate\\Clear_10";
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(fileName, null, new File(dirName));
BufferedReader input = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
}//end while
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
}//end try
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}//end catch`
我得到这个错误:
产生java.io.IOException:不能运行程序 “mp3wrap.exe”(目录 “E:\音乐\新建文件夹\ ZZ Concatinate \ Clear_10”) :CreateProcess error = 2,系统找不到指定的文件
给全程?你可以详细阐述一下吗? – 2014-03-05 08:35:38
@Zedai:在Windows'“C:\\ Programs \\ tools \\ audio \\ JoinTheParty \\ Player \\ mp3wrap.exe”“或类似的东西。例如,在Linux'“/ usr/local/bin/mp3wrap”中。 –
重读这个问题并延长我的答案。 –