Note: Some of these may not be available on all Unix platforms, since there is some variation. These constants are defined where they are defined by the underlying platform.
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.
如果您在POSIX平台上,您可以通过^{} 模块访问
sysexit.h
中的常量:编辑:这些常量可通过^{} 模块在所有平台上使用。在
^{} 模块提供了几个可以使用的退出代码常量。在
关于便携性
虽然退出代码可能有用,但它们可能会带来可移植性问题。文件警告:
因此,如果您想使用退出代码,并且您的代码需要是可移植的,那么您必须进行更多的错误检查。^{} 文档建议在失败时使用字符串错误消息或整数1。在
^{pr2}$对于成功退出:
考虑到退出代码带来的额外复杂性,如果您实际上不需要它们,那么最好跳过它们。在
参见documentation for ^{} 。在
相关问题 更多 >
编程相关推荐