Python退出代码 [英] Python exit codes

查看:35
本文介绍了Python退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到有关 Unix 上python"进程退出代码含义的信息?例如,如果我执行python thisfiledoesntexist.py",我会得到退出代码 2

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

总结:

from errno import errorcode
print errorcode[2]

推荐答案

如前所述,大部分错误代码来自执行的脚本和 sys.exit().

As stated, mostly the error codes come from the executed script and sys.exit().

将不存在的文件作为解释器参数的示例属于不同的类别.尽管我没有猜测到,但这些退出代码是标准"代码.Linux 错误代码.有一个名为 errno 的模块提供了这些错误编号(退出代码来自 linux/include/errno.h.

The example with a non-existing file as an argument to the interpreter fall in a different category. Though it's stated nowhere I would guess, that these exit codes are the "standard" Linux error codes. There is a module called errno that provides these error numbers (the exit codes come from linux/include/errno.h.

即:errno.ENOENT(代表没有这样的文件或目录")的数字 2 与您的示例一致.

I.e.: errno.ENOENT (stands for for "No such file or directory") has the number 2 which coincides with your example.

这篇关于Python退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆