使用 Python subprocess 库,为什么没有捕获到 “git push”的输出?

使用 Python subprocess 库,为什么没有捕获到 “git push”的输出?

问题描述:

需求:因为连接 github 的网络不稳定,就想写一个脚本在失败的时候,自动重新提交
查了一下资料,因为使用的是 python3.9 所以采用 subprocess 库进行实现
遇到了现在这个问题,使用 stdout=subprocess.PIPE 开放了通道,但 r.stdout 却没有捕获到命令行 git push 的输出

关于下图,红框标记有点错误 还请见谅

img

捕获输出请使用 subprocess.check_output