从java执行命令行工具与命令行不同?
我的问题是关于 apache commons 中的 org.apache.commons.exec.DefaultExecutor.execute(CommandLine command) 方法。
这是执行 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);
当我从 Java 执行命令行工具 ec ffmpeg 时,如下所示:
/path_to_ffmpeg/ffmpeg -i "/My Media/Video/Day2/VIDEO.MOV"
ffmpeg 的结果是它找不到为输入指定的文件
"/My Media/Video/Day2/VIDEO.MOV": No such file or directory
如果我在控制台中以完全相同的方式执行命令工作没有任何问题。 将“My Media”文件夹重命名为“MyMedia”可以从 Java 端解决问题,但对我来说这不是一个可用的解决方案。
如何解决此问题而无需限制输入路径的空格?
My question is regarding the org.apache.commons.exec.DefaultExecutor.execute(CommandLine command) method in apache commons.
This is the codebit for executing 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);
When I execute a command line tool e.c. ffmpeg from Java like this:
/path_to_ffmpeg/ffmpeg -i "/My Media/Video/Day2/VIDEO.MOV"
The result of ffmpeg is that it can not find the file specified for input
"/My Media/Video/Day2/VIDEO.MOV": No such file or directory
If I execute the command in my console the exact same way it works without any problems.
Renaming the "My Media" Folder to "MyMedia" fixes the problem from the Java side, but for me that is not a usable solution.
How can I fix this without having to restrict spaces from the input path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://commons.apache.org/exec/tutorial.html 中的示例建议你做类似的事情:
The examples at http://commons.apache.org/exec/tutorial.html suggest that you do something like: