Reputation: 2217
My Script always terminates abruptly because the command I'm executing using subprocess.check_call()
or subprocess.check_output()
This is the Error.
File "C:\Python34\lib\subprocess.py", line 620, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '['C:\\Program Files\\info.exe','-student', 'Tony']' returned non-zero exit status 2
How do I avoid abnormal termination of the Script in such cases ? I've tried piping the Error/Exception to STDOUT but that didn't seem to help.
op = subprocess.check_output([installpath+'\\info.exe','-student', name],stderr=subprocess.STDOUT)
I did read that using subprocess.call()
. I'm not sure if subprocess.call() is inferior to subprocess.check_output()
& subprocess.check_call()
Upvotes: 0
Views: 1433
Reputation: 10513
try:
# start a subprocess
except CalledProcessError:
# do something if it fails.
Upvotes: 1