I'd like to capture standard output as a string when running a subprocess from Python 3.9. At the same time, I would like standard error to stream to my console for debugging that lengthy subprocess.
Popen.communicate() has related functionality, but it seems that subprocess, as a high-level API, is preferable; and I am not sure how to treat the two streams separately.
This code returns the two of them as strings. How can I just stream stderr?
process = subprocess.run( ['sh', script], capture_output=True, text=True, env=env)
if process.returncode:
raise Exception(f"Error {process.returncode} {process.stderr}")
return process.stdout