Realtime Output from Subprocess
When executing command line programs using Python's subprocess module, developers often encounter the issue of buffered output. This can be problematic for tasks that require line-by-line processing.
To resolve this issue, users can consider the following approach:
while True: line = p.stdout.readline() if not line: break # No more output, exit loop # Process the current line as needed...
This method allows for real-time output processing without encountering buffering issues. Despite initial attempts with for line in p.stdout: and bufsize settings, this approach has been proven to effectively capture output in a timely manner.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!