if p.poll() != None:
    break
print('program ended')
print('stdout:', ''.join(stdout))
print('stderr:', ''.join(stderr))
Can you make a python subprocess output stdout and stderr as usual, but also capture the output as a string?