从java执行命令行工具与命令行不同?

发布于 2024-09-02 21:45:18 字数 904 浏览 1 评论 0原文

我的问题是关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御弟哥哥 2024-09-09 21:45:18

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\"");

The examples at http://commons.apache.org/exec/tutorial.html suggest that you do something like:

DefaultExecutor de = new DefaultExecutor();
de.execute(CommandLine.parse("/path_to_ffmpeg/ffmpeg -i \"/My Media/Video/Day2/VIDEO.MOV\"");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文