簡體   English   中英

python subprocess.Popen捕獲大量輸出

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM