Alex Rivera | Logout

Handling exit code returned by python in shell script

Asked 2013-01-10T14:01:36.760
20

I am calling a python script from within a shell script. The python script returns error codes in case of failures.

How do I handle these error codes in shell script and exit it when necessary?

Edit
Report

1 Answer

5

You mean the $? variable?

$ python -c 'import foobar' > /dev/null
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named foobar
$ echo $?
1
$ python -c 'import this' > /dev/null
$ echo $?
0
answered 2013-01-10T14:04:56.937

Your Answer