当您传递时
shell=True,Popen需要一个字符串参数,而不是列表。因此,当您执行此操作时:
p1 = Popen(['echo','hello'], stdout=PIPE, shell=True)
这是怎么回事:
execve("/bin/sh", ["/bin/sh", "-c", "echo", "hello"], ...)也就是说,它调用
sh -c"echo",并被
hello有效地忽略(从技术上讲,它成为shell的位置参数)。这样,shell运行
echo,打印
n,这就是为什么在输出中看到它的原因。
如果使用
shell=True,则需要执行以下操作:
p1 = Popen('echo hello', stdout=PIPE, shell=True)


