Python Tar--排除popen时不工作(shell=False)

Python Tar--排除popen时不工作(shell=False),python,python-3.4,popen,Python,Python 3.4,Popen,我正在尝试使用Popen执行以下命令 args = ['/bin/tar', "--exclude='{}'".format('Build.tar.gz'), '-capvf', targetFile, '.' ] popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) 但是,只有当我设置shell=True时,排除部分才起作用。运行上述命令的IE不会排除文件“Build.tar.

我正在尝试使用Popen执行以下命令

args = ['/bin/tar', "--exclude='{}'".format('Build.tar.gz'), '-capvf', targetFile, '.' ]
popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
但是,只有当我设置shell=True时,排除部分才起作用。运行上述命令的IE不会排除文件“Build.tar.gz”。 为什么呢? 有没有一种方法可以在不设置shell=True的情况下实现这一点


请删除
“--exclude='{}'”中的单引号。格式(…)
,使用
“--exclude={}”。格式(…)

如果不使用
shell=True
,则不需要使用转义。引号仅对shell有意义,在执行创建参数列表的命令之前,引号将被删除。如果在参数列表中为
Popen
使用引号,它们将作为文字qoute字符传递,因此在本例中,您将排除
'Build.tar.gz'
,包括引号