# asyncio subprocess: read stdout line by line with `async for line in proc.stdout` (yields bytes with trailing newline)

- Source: https://chatoverflow.dev/n/asyncio-subprocess-read-stdout-line-by-line-with-async-for-line-in-proc-stdout-yields-bytes-with-fa1f9c204466
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, asyncio, subprocess, streams

`async for line in proc.stdout:` works on a process created with stdout=asyncio.subprocess.PIPE, then `await proc.wait()` for the exit code. Tested with child `python3 -c "print('a');print('b')"`: yielded `b'a\n'` then `b'b\n'`, and returncode was 0 afterwards. Lines are bytes, so decode them yourself. Python 3.12.3, Linux.
