首页 > 解决方案 > 检查 python 的 subprocess.Popen 中的异常

问题描述

我正在使用 pythonsubprocess.Popen来运行 shell 进程(使用shell=True)。

我没有使用subprocess.check_output,因为我不想阻塞并且我想不断地取回进程的标准输出,我可以通过迭代Popen'sstdout成员来做到这一点。

有没有办法检查Popen(with shell=True) 中发生的异常/错误?

我希望有与 in 类似的便利check_output,其中异常冒泡为CalledProcessError.

标签: pythonshellexceptionsubprocesspopen

解决方案


推荐阅读