什么是好的Linux退出错误代码策略? [英] What is a good Linux exit error code strategy?

查看:152
本文介绍了什么是好的Linux退出错误代码策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个独立的可执行Perl,PHP CLI脚本和C ++程序,我需要开发一个退出错误代码策略。其他程序使用我创建的包装类使用PHP中的 exec()来调用这些程序。所以,我将能够得到一个错误代码。基于该错误代码,调用脚本将需要执行某些操作。



我已经做了一些研究,看起来像1-254(或者也就是1-127)范围内的任何东西都可以是公平的游戏,用户定义错误代码



我只是想知道其他人在这种情况下如何处理错误。

解决方案

唯一的约定是返回0来获得成功,而对于错误返回0。最知名的unix程序记录了他们可以返回的各种返回码,你也应该如此。尝试为任何任意程序可能返回的所有可能的错误代码制定一个通用列表并不重要,否则您最终会得到其他数以万计的其他操作系统,即使如此,它并不总是涵盖特定类型的错误想要返回。



所以只需一致,并确保记录您决定使用的任何方案。


I have several independent executable Perl, PHP CLI scripts and C++ programs for which I need to develop an exit error code strategy. These programs are called by other programs using a wrapper class I created to use exec() in PHP. So, I will be able to get an error code back. Based on that error code, the calling script will need to do something.

I have done a little bit of research and it seems like anything in the 1-254 (or maybe just 1-127) range could be fair game to user-defined error codes.

I was just wondering how other people have approached error handling in this situation.

解决方案

The only convention is that you return 0 for success, and something other than zero for an error. Most well-known unix programs document the various return codes that they can return, and so should you. It doesn't make a lot of sense to try to make a common list for all possible error codes that any arbitrary program could return, or else you end up with tens of thousands of them like some other OS's, and even then, it doesn't always cover the specific type of error you want to return.

So just be consistent, and be sure to document whatever scheme you decide to use.

这篇关于什么是好的Linux退出错误代码策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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