The difference between sys.exit (1) and sys.exit (2) of python

if not cmdname:

    _print_commands(settings, inproject)
    sys.exit(0)

elif cmdname not in cmds:

    _print_unknown_command(settings, cmdname, inproject)
    sys.exit(2)
    

the difference between sys.exit (2) and sys.exit (1) here
I don"t know why.

Mar.07,2022

sys.exit ([args]) Parameter parsing

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.

means that when the parameter is a number, the meaning of the shell exit code is the same as that of the sys.exit (2) and sys.exit (1) just to distinguish the end reason

.
  • 0 : end successfully
  • 1 : general error
  • 2 : misuse the Shell command
Menu