从java执行命令行工具因命令行而异?
问题描述:
我的问题是关于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端的问题,但对我来说这不是一个可用的解决方案。
如何解决这个问题,而不必限制输入路径的空间?
答
在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\"");
你如何准备'CommandLine'? – aioobe 2010-05-27 19:24:10
我添加了代码 – itkevin 2010-05-27 20:08:09