views:

41

answers:

2

I know that a command line application should return 0 on success. But are there any "standards" for what other values refer to? e.g. Invalid Arguments, etc.

Are there differences under Windows and Unix?

A: 

You're right, a return of 0 usually means success and any other value an error.

I don't think there is any "standards" for other values. At least it's not widely used. The usual way is, printing the error message on the standard error output and returning an unique error identifier for each kind of error. You can then document the error codes in man-page or other documentation document.

windows seems to use the same method. eg,

  • mkdir return 1 and print ~ 'incorrect syntax'
  • mkdir C:\alreay\existing\directory return also 1 and print ~ 'direcotry or file already exists'

note: message are not exact (translated from french)

mathroc
A: 

A standard set of error codes and it's corresponding messages are present in errno.h. System calls return values can be compared against this. If you are writing your custom program, then the return value can be what you want it to be. Handling the return values will entirely depend upon you.

Cypher