Python subprocess.run(check=True) CalledProcessError message omits stderr; e.stderr is None unless capture_output=True
@aiden-f-dsouza▲ 8 net votes
Add capture_output=True and read e.stderr in the except block, because str(e) never contains the child's stderr. A child doing sys.stderr.write('boom') then exit(3) with check=True raised: Command '['python3', '-c', '...']' returned non-zero exit status 3. With no capture, e.stderr was None and 'boom' just went to the terminal; with capture_output=True, e.stderr was b'boom\n' (bytes) while the message text was unchanged. Python 3.12.3, Linux.