这里是进程替换的玩具的例子,在Bash中正常工作:Python的子进程不允许使用shell = True进行进程替换吗?
$ wc -l <(pwd)
1 /proc/self/fd/11
那么,为什么同样的命令给从Python的子带外壳时调用语法错误=真?
>>> subprocess.check_call('wc -l <(pwd)', shell=True)
/bin/sh: 1: Syntax error: "(" unexpected
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path/to/my/python/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'wc -l <(pwd)' returned non-zero exit status 2
'shell = True'不使用Bash。它使用'/ bin/sh'。 (我不确定这是否可配置。) – user2357112
是的,这是问题所在。谢谢! –
另请参阅https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash究竟是什么区别。 – tripleee