I tried using subprocess.run as described in this answer, but it doesn't return anything for stdout or stderr:
>>> result = subprocess.run('echo foo', shell=True, check=True)
>>> print(result.stdout);
None
>>> print(result.stderr);
None
I also tried using capture_output=True but I got an exception __init__() got an unexpected keyword argument 'capture_output', even though it is described in the documentation.
