如何将空参数传递给Popen(使用shell = False)?

Mac*_*arz 3 python

我有外部脚本(sh),我想做这样的事情:

arg1 = 'some string'
arg2 = 'some string2'
arg3 = ''

cmd = ['/usr/local/bin/myscript', 'arg1', 'arg2', 'arg3']
Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)
Run Code Online (Sandbox Code Playgroud)

我似乎认为,如果“ arg3”为空,则仅使用两个参数调用了我的脚本,如果为空,如何传递“ arg3”事件?

unu*_*tbu 5

test.py:

import sys
print(sys.argv)
Run Code Online (Sandbox Code Playgroud)

test2.py:

import subprocess
import shlex

cmd="test.py 'some string' 'some string2' '' "
proc=subprocess.Popen(shlex.split(cmd))
Run Code Online (Sandbox Code Playgroud)

运行test2.py产生

['test.py', 'some string', 'some string2', '']
Run Code Online (Sandbox Code Playgroud)