开发者

How to pass empty argument to Popen (with shell=False)?

I have external script (sh), i would like to do something like this:

arg1 = 'some string'
arg2 = 'some string2'
arg3 = ''
开发者_如何学Python
cmd = ['/usr/local/bin/myscript', 'arg1', 'arg2', 'arg3']
Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)

I seems, that if "arg3" is empty, my script i called only with two arguments, how can I pass "arg3" event if it's empty?


test.py:

import sys
print(sys.argv)

test2.py:

import subprocess
import shlex

cmd="test.py 'some string' 'some string2' '' "
proc=subprocess.Popen(shlex.split(cmd))

Running test2.py yields

['test.py', 'some string', 'some string2', '']


Mayby arg3 = '""' ?


Popen(cmd[0] + [ repr(x) for x in cmd[1:]], 
shell=False, 
stdin=PIPE, 
stdout=PIPE, 
stderr=PIPE)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜