2010-05-27 185 views
2

我的问题是关于apache commons中的org.apache.commons.exec.DefaultExecutor.execute(CommandLine命令)方法。从java执行命令行工具因命令行而异?

这是用于执行的ffmpeg的码位:

command = FFMPEG_DIR + "ffmpeg -i \"" + file.getAbsolutePath() + "\""; 
DefaultExecutor executor = new DefaultExecutor(); 
ByteArrayOutputStream baos = new ByteArrayOutputStream(); 

PumpStreamHandler streamHandler = new PumpStreamHandler(baos); 
executor.setStreamHandler(streamHandler); 

CommandLine commandLine = CommandLine.parse(command); 

executor.execute(commandLine); 

当我执行的命令行工具E.C. ffmpeg的从Java这样的:

/path_to_ffmpeg/ffmpeg -i "/My Media/Video/Day2/VIDEO.MOV" 

的ffmpeg的结果是,它无法找到输入

"/My Media/Video/Day2/VIDEO.MOV": No such file or directory 

规定如果我在控制台执行命令它工作没有完全相同的方式文件任何问题。 将“我的媒体”文件夹重命名为“MyMedia”可以解决Java端的问题,但对我来说这不是一个可用的解决方案。

如何解决这个问题,而不必限制输入路径的空间?

+0

你如何准备'CommandLine'? – aioobe 2010-05-27 19:24:10

+0

我添加了代码 – itkevin 2010-05-27 20:08:09

回答

1

http://commons.apache.org/exec/tutorial.html的例子表明,你做这样的事情:

DefaultExecutor de = new DefaultExecutor(); 
de.execute(CommandLine.parse("/path_to_ffmpeg/ffmpeg -i \"/My Media/Video/Day2/VIDEO.MOV\""); 
+0

我在执行之前解析了命令。同样的问题 – itkevin 2010-05-27 19:33:13

+0

那么如果你通过'addArgument'方法呢? – aioobe 2010-05-27 20:26:21

+0

同样的结果。当我将工作目录更改为“/ My Media/Video/Day2”时,它适用于没有空格的文件?!?我花了整整一天的时间,我无法弄清楚它:( – itkevin 2010-05-27 21:44:39