0

我从 python 脚本调用 subprocess.Popen 然后调用通信

process = subprocess.Popen(cmds, shell=shell, stdout=subprocess.PIPE,  
                               stderr=subprocess.PIPE)  

stdout, stderr = process.communicate()

这样做的问题是标准输出被缓冲并且只会捕获一定数量的字符。

问题是,如何获得我生成的进程的完整标准输出和完整标准错误?

4

1 回答 1

0

几点。

如果您将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 都将存储在内存中。

于 2012-07-04T04:29:46.263 回答