尽管没有错误,但 Popen 的通信输出具有非空的 stderr

问题描述

我正在尝试了解 Python 的 br0 模块 stdout_datastderr_datasubprocess 的行为。当命令的输出稍大时,stderr 为非空。 stdout 有预期的输出。在下面的示例中,输出的大小仅为几 KB 而不是 MB。 Official documentation 有此注释

(Popen.communicate())

我假设它指的是 GB 的输出并且无法放入 RAM。它不应该适用于我的情况。

问题的最小工作示例。

Note: The data read is buffered in memory,so do not use this method if the data size is large or unlimited. 

import subprocess def test(): # cmd = ["curl","www.google.com"] # This has non-empty content in stderr cmd = ["echo","Hello World"] # This has empty stderr p = subprocess.Popen(cmd,stdout = subprocess.PIPE,stderr = subprocess.PIPE,shell=False) stdout,stderr = p.communicate() if stderr: print("Failed") if __name__ == "__main__": test() cmd = ["curl","www.google.com"] 内容是下载的数据量(接收的字节数、传输的字节数、平均速度等)时

我正在尝试了解发生这种情况的内部原因。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)