I got a message saying "script xyz.py returned exit code 0". What does this mean?
What do the exit codes in python mean? How many are there? How many are important?
I got a message saying "script xyz.py returned exit code 0". What does this mean?
What do the exit codes in python mean? How many are there? How many are important?
Exit codes of 0 usually mean, "nothing wrong here." However if the programmer of the script didn't follow convention you may have to consult the source to see what it means. Usually a non-zero value is returned as an error code.
The exit codes only have meaning as assigned by the script author. The Unix tradition is that exit code 0 means 'success', anything else is failure. The only way to be sure what the exit codes for a given script mean is to examine the script itself.
Exit codes in many programming languages are up to programmers. So you have to look at your program source code (or manual). Zero usually means "everything went fine".
What you're looking for in the script is calls to sys.exit(). The argument to that method is returned to the environment as the exit code.
It's fairly likely that the script is never calling the exit method, and that 0 is the default exit code.
Quote from http://www.wingware.com/psupport/python-manual/2.6/library/sys.html (about sys.exit())
"The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like. Most systems require it to be in the range 0-127, and produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors."
One example where exit codes are used are in shell scripts. In bash you can check the special variable $? for the last exit status:
me@mini:~$ echo
mike@mini:~$ echo $?
0
me@mini:~$ eccho
-bash: eccho: command not found
me@mini:~$ echo $?
127
Personally I try to use the exit codes I find in /usr/include/asm-generic/errno.h (on a linux system), but I don't know if this is the right thing to do.
Operating system commands have exit codes. Look for linux exit codes to see some material on this. The shell uses the exit codes to decide if the program worked, had problems, or failed. There are some efforts to create standard (or at least commonly-used) exit codes. See this Advanced Shell Script posting.
There is a errno module that defines standard system symbol:
http://docs.python.org/library/errno.html
For example, Permission denied is error code 13:
import errno, sys
if can_access_resource():
do_something()
else:
sys.exit(errno.EACCES)