Python exit codes

后端 未结 4 1037
失恋的感觉
失恋的感觉 2021-02-18 22:11

Where can I find information about meaning of exit codes of \"python\" process on Unix? For instance, if I do \"python thisfiledoesntexist.py\", I get exit code 2

Summar

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-18 22:54

    The Python manual states this regarding its exit codes:

    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.

    So, since you specified thisfiledoesntexist.py as a command line argument, you get a return code of 2 (assuming the file does not, in fact, exist. In that case I'd recommend renaming it to thisfiledoesexist.py. ;) )

    Other that such parsing errors, the return code is determined by the Python program run. 0 is returned unless you specify another exit code with sys.exit. Python itself does not interfere.

提交回复
热议问题