Python 3.x 如何使用subprocess在Python中调用一个参数周围带有双引号的应用程序?

Python 3.x 如何使用subprocess在Python中调用一个参数周围带有双引号的应用程序?,python-3.x,certutil,Python 3.x,Certutil,我试图从python内部调用certutil。但是,我需要使用引号,并且一直无法这样做。我的代码如下: import subprocess output= subprocess.Popen(("certutil.exe", "-view", '-restrict "NotAfter <= now+30:00, NotAfter >= now+00:00"' ), stdout=subprocess.PIPE).stdout for line in output: print(

我试图从python内部调用certutil。但是,我需要使用引号,并且一直无法这样做。我的代码如下:

import subprocess
output= subprocess.Popen(("certutil.exe", "-view", '-restrict "NotAfter <= now+30:00, NotAfter >= now+00:00"' ), stdout=subprocess.PIPE).stdout
for line in output:
    print(line)

output.close()
出于某种原因,它似乎正在将
翻译成
\


有人能解释为什么以及如何修复它吗?

我没有安装任何版本的Python。但根据的回答和文档,子流程自动处理带空格参数的双引号要求

因此,您需要简单地使用:

import subprocess
output= subprocess.Popen(("certutil.exe", "-view", "-restrict", "NotAfter <= now+30:00, NotAfter >= now+00:00" ), stdout=subprocess.PIPE).stdout
for line in output:
    print(line)

output.close()
导入子流程
output=subprocess.Popen(((“certutil.exe”、“-view”、“-restrict”、“NotAfter=now+00:00”),stdout=subprocess.PIPE)。stdout
对于行输入输出:
打印(行)
output.close()
调用certutil时使用的命令行是:

certutil.exe -view -restrict "NotAfter <= now+30:00, NotAfter >= now+00:00"
certutil.exe-查看-限制“NotAfter=now+00:00”
output=subprocess.Popen((“certutil.exe-view-restrict\“NotAfter=now+00:00\”),stdout=subprocess.PIPE)。stdout
这就是所需要的。我将命令作为一个带有2个参数的命令传递。我应该做的是将它作为一个带有2个参数的大命令传递

certutil.exe -view -restrict "NotAfter <= now+30:00, NotAfter >= now+00:00"
output=subprocess.Popen(("certutil.exe -view -restrict  \"NotAfter<=now+30:00,NotAfter>=now+00:00\"" ),stdout=subprocess.PIPE).stdout