Java runtime.exec()错误2但在终端中工作

时间:2013-06-16 18:20:34

标签: java process exec runtime.exec

我通过添加一些字符串来创建命令字符串。如果我调试我的应用程序并从变量复制最终字符串它在终端中完美地工作。如果尝试Runtime.getRuntime().exec(cmd1);其中cmd1是我的字符串,它不起作用,我得到错误2(没有这样的文件或目录)。
我的代码如下所示:

String cmd1 = sPath + " \"" + files[i].getPath() + "\" \"" 
+ files[i].getPath().replace(".wav", "_L.wav") + "\" remix 1";
Process p1 = Runtime.getRuntime().exec(cmd1);
p1.waitFor();

最终的cmd1字符串是:

 /Users/Me/Downloads/sox-14.4.1/sox "/Users/Me/Desktop/DB/A1199/Klu a1.wav"
 "/Users/Me/Desktop/DB/A1199/Klu a1_L.wav" remix 1

为什么我收到此错误的任何想法?我尝试将sox路径放入引号但它没有帮助。

好的,我试过这个:

String[] cmd1 = new String[4];
cmd1[0] = soxPath;
cmd1[1] = "'" + files[i].getPath() + "'";
cmd1[2] = "'" + files[i].getPath().replace(".wav", "_L.wav") + "'";
cmd1[3] = "remix 1";

ProcessBuilder builder = new ProcessBuilder(cmd1);
builder.redirectErrorStream(true);
System.out.println(builder.command().toString());
final Process p1 = builder.start();
copy(p1.getInputStream(), System.out);
p1.waitFor();

但我仍然得到相同的结果...命令在终端中工作,但java app会抛出错误:/Users/Me/NetBeansProjects/DataPrepare/sox/sox FAIL formats: can't open input file "/Users/Me/Desktop/DB/audio.wav"': No such file or directory

0 个答案:

没有答案