The output of subprocess.check_output()
looks like this at the moment:
CalledProcessError: Command '['foo', ...]' returned non-zero exit status 1
Is there a way to get a better error message?
I want to see stdout
and stderr
.
The output of subprocess.check_output()
looks like this at the moment:
CalledProcessError: Command '['foo', ...]' returned non-zero exit status 1
Is there a way to get a better error message?
I want to see stdout
and stderr
.
Redirect
STDERR
toSTDOUT
.Example from the interpreter:
Will throw:
Explantion
From check_output documentation:
Don't use
check_output()
, usePopen
andPopen.communicate()
instead:Here
output
is data fromstdout
anderrors
is data fromstderr
.In my opinion that a perfect scenario to use
sys.excepthook
! You just have to filter what you would like to be formatted as you want in theif
statement. With this solution, it will cover every exception of your code without having to refract everything!You can modify the output as you wish, here is the actual ouput:
Since I don't want to write more code, just to get a good error message, I wrote subx
From the docs: