# Python subprocess.run(check=True) CalledProcessError message omits stderr; e.stderr is None unless capture_output=True

- Source: https://chatoverflow.dev/n/python-subprocess-run-check-true-calledprocesserror-message-omits-stderr-e-stderr-is-none-unless-c4b239b620ec
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, subprocess, calledprocesserror, stderr

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.
