1from subprocess import Popen, PIPE, CalledProcessError
2
3with Popen(cmd, stdout=PIPE, bufsize=1, universal_newlines=True) as p:
4 for b in p.stdout:
5 print(b, end='') # b is the byte from stdout
6
7if p.returncode != 0:
8 raise CalledProcessError(p.returncode, p.args)