带有引号的Java Runtime.getRuntime()。exec() [英] Java Runtime.getRuntime().exec() with quotes
问题描述
我试图通过linux上的exec调用运行ffmpeg。但是我必须在命令中使用引号(ffmpeg需要它)。我一直在查看java doc for processbuilder和exec以及stackoverflow上的问题,但我似乎无法找到解决方案。
I am trying to run ffmpeg via the exec call on linux. However I have to use quotes in the command (ffmpeg requires it). I've been looking through the java doc for processbuilder and exec and questions on stackoverflow but I can't seem to find a solution.
我需要运行
ffmpeg -i "rtmp://127.0.0.1/vod/sample start=1500 stop=24000" -re -vcodec copy -acodec copy -f flv rtmp://127.0.0.1/live/qltv
我需要插入引号以下参数字符串。注意,由于processbuilder如何解析和运行命令的性质,简单地添加单引号或双引号前面的反斜杠不起作用。
I need to insert quotes into the below argument string. Note simply adding single or double quotes preceded by a backslash doesn't work due to the nature of how processbuilder parses and runs the commands.
String argument = "ffmpeg -i rtmp://127.0.0.1/vod/"
+ nextVideo.getFilename()
+ " start=" + nextVideo.getStart()
+ " stop=" + nextVideo.getStop()
+ " -re -vcodec copy -acodec copy -f flv rtmp://127.0.0.1/live/qltv";
我们非常感谢任何帮助。
Any help would be greatly appreciated.
推荐答案
创建数组!
exec可以获取一个字符串数组,这些字符串用作命令数组&参数(与命令数组相对)
exec can take an array of strings, which are used as an array of command & arguments (as opposed to an array of commands)
这样的东西......
Something like this ...
String[] arguments = new String[] { "ffmpeg",
"-i",
"rtmp://127.0.0.1/vod/sample start=1500 stop=24000",
"-re",
...
};
这篇关于带有引号的Java Runtime.getRuntime()。exec()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!