将双引号shell命令在python中传递给subprocess.Popen()?

我一直试图传递一个命令在shell中工作,只在文本双引号在命令行中的“concat:file1 | file2”参数ffmpeg。

我不能让这个工作从python与subprocess.Popen()。任何人都有一个想法如何传递报价到子过程。

这里是代码

command = "ffmpeg -i "concat:1.ts|2.ts" -vcodec copy -acodec copy temp.mp4"

output,error = subprocess.Popen(command,universal_newlines=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

当我这样做,ffmpeg将不会采取任何其他方式,而不是引号周围的连接区。有没有办法成功地传递这行到subprocess.Popen命令?

我建议使用列表形式的调用,而不是引用的字符串版本:
command = ["ffmpeg","-i","concat:1.ts|2.ts","-vcodec","copy","-acodec","temp.mp4"]
output,error  = subprocess.Popen(
                    command,stderr=subprocess.PIPE).communicate()

这更准确地表示将要传递到结束进程的准确的参数集,并且消除了对shell引用的需要。

也就是说,如果你绝对要使用纯字符串版本,只需使用不同的引号(和shell = True):

command = 'ffmpeg -i "concat:1.ts|2.ts" -vcodec copy -acodec copy temp.mp4'
output,shell=True,stderr=subprocess.PIPE).communicate()

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...