Python 3.5 引入了模块中的run()
函数subprocess
作为新推荐的高级子进程调用方法。
在三个较旧的(自 Python 2.5 / 2.7 起可用)高级 API 函数中,check_call()
. Python 3.5 文档声称check_call()
[...] 相当于:
run(..., check=True)
该文档还警告不要传递subprocess.PIPE
asstdout
或stderr
to check_call()
:
笔记
请勿使用
stdout=PIPE
或stderr=PIPE
与此功能一起使用。如果子进程生成足够的输出到管道以填满操作系统管道缓冲区,则子进程将阻塞,因为管道没有被读取。
由于它是“等效的”,因此此警告是否也适用于run(..., check=True)
,即应该
subprocess.run(..., stdout=subprocess.PIPE, check=True)
和
subprocess.run(..., stderr=subprocess.PIPE, check=True)
也要避免吗?(的文档run()
没有提到这个警告。)