About Reading Pipe Output from a Shell Command

You can read the pipe output of a shell command line by line using sys.stdin:

1
2
3
4
import sys

for line in sys.stdin.read().splitlines():
    print(line)

Tips and Tricks Programming Python 3