subprocess.Popen没有正确转义命令行参数?

dee*_*eeb 4 python json curl cordova

我试图用python调用以下curl命令:

curl -k -F file=@something.zip -F "data={\\"title\\":\\"Another App\\"}" -Lu usr:pwd https://build.phonegap.com/api/v0/apps
Run Code Online (Sandbox Code Playgroud)

为了它的工作,我发现我传入数据的json需要使用反斜杠进行转义.

我可以用...来调用这个命令

os.system(curl -k -F file=@something.zip -F "data={\\"title\\":\\"Another App\\"}" -Lu usr:pwd https://build.phonegap.com/api/v0/apps)
Run Code Online (Sandbox Code Playgroud)

它的工作原理.

但是,当我尝试使用像这样的子进程模块时......

s = 'curl -k -F file=@something.zip -F "data={\\"title\\":\\"Another App\\"}" -Lu usr:pwd https://build.phonegap.com/api/v0/apps'
push = subprocess.Popen(s.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, errors = push.communicate()
print output
Run Code Online (Sandbox Code Playgroud)

...卷曲不起作用,我从api我得到一个错误,我正在使用无效参数,这是我在过去使用不正确的转义json时得到的.

这里发生了什么?为什么我可以用os.system调用这个命令而不是subprocess.Popen?到目前为止,我的假设是分裂正在搞乱字符串中的某些东西,但是当我检查输出时,我没有发现任何看起来错误的东西s.split().

fra*_*sua 7

也许使用shell = True

push = subprocess.Popen(s, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)