Java ProcessBuilder: space within quotation marks

喜你入骨 提交于 2019-12-23 17:43:15

问题


I am using ProcessBuilder to run FFMPEG to convert and label some of my MP3-Files.

Manually using the following in a .bat file works as expected:

"E:\Dokumente\workspace\MusicBot\ffmpeg\bin\ffmpeg.exe" 
    -i "The Glitch Mob - We Can Make The World Stop.mp4" 
    -metadata author="The Glitch Mob" 
    -metadata title="We Can Make The World Stop" 
    -ab 320k "mob.mp3"

Now what i am trying to achieve using java's ProcessBuilder

ProcessBuilder pr = new ProcessBuilder(FFMPEG_PATH, 
    "-i", target.getAbsolutePath(),
    "-metadata", "title=\"We Can Make The World Stop\"", 
    "-metadata", "author=\"The Glitch Mob\"", 
    "-ab", "320k", 
    tar.getAbsolutePath());

results in a [NULL @ 000000000032f680] Unable to find a suitable output format for 'Can'. Using title and author without spaces in them works, however.


回答1:


The double quotes on the command line are there to tell the shell interpreter not to split your string into multiple parameters. This is to ensure that the application receives title=We Can Make The World Stop as a single argument.

Since ProcessBuilder handles multiple command line arguments explicitly, there's no need for escaping whitespace when calling it.



来源:https://stackoverflow.com/questions/23933335/java-processbuilder-space-within-quotation-marks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!