Java ProcessBuilder:引号内的空格 [英] Java ProcessBuilder: space within quotation marks

查看:95
本文介绍了Java ProcessBuilder:引号内的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ProcessBuilder运行FFMPEG来转换和标记我的一些MP3文件.

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

在.bat文件中手动使用以下内容即可正常工作:

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"

现在我正在尝试使用Java的ProcessBuilder实现

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());

导致 [NULL @ 000000000032f680]无法找到'Can'的合适输出格式.但是,使用标题和作者时不能使用空格.

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

推荐答案

在命令行中使用双引号可以告诉Shell解释器不要将您的字符串拆分为多个参数.这是为了确保应用程序将 title =我们可以使世界停止作为单个参数.

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.

由于 ProcessBuilder 可显式处理多个命令行参数,因此在调用时无需转义空格.

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

这篇关于Java ProcessBuilder:引号内的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆