I'm trying to redirect stderr to stdout and read the output of a command. It looks like the code works, but when it reaches the end of the output, it throws an exception
Code:
with Popen(["bash", "-c", "for ((i=0;i<10;i++)); do echo $i; sleep .5; done"],
stderr=subprocess.STDOUT) as proc:
out, err = proc.communicate()
for line in out:
if line:
print(line)
Output:
0
1
2
3
4
5
6
7
8
9
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-28-3c150d6a4092> in <module>()
2 stderr=subprocess.STDOUT) as proc:
3 out, err = proc.communicate()
----> 4 for line in out:
5 if line:
6 print(line)
TypeError: 'NoneType' object is not iterable