[英]python subprocess.Popen capture lots of output
我正在从python脚本调用subprocess.Popen,然后调用communication
process = subprocess.Popen(cmds, shell=shell, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
这样做的问题是stdout会被缓冲,并且只会捕获一定数量的字符。
问题是,如何获得所生成进程的完整stdout和完整stderr?
几点。
如果您将PIPE用于stdout / stderr ,并且Popened进程开始写入大量数据,并且在您的进程中您没有读取任何stdout / stderr,则Popened进程将阻塞 。 这是一种表述为
Note
Do not use stdout=PIPE or stderr=PIPE with this function. As the pipes are not being read in the current process, the child process may block if it generates enough output to a pipe to fill up the OS pipe buffer.
关于您指出的其他说明。 仅当您使用stdout = None,stderr = None进行 Popen时才适用。 在这种情况下,所有Popened进程的 out / err都将存储在内存中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.