ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
OK me again. I assume were dealing with BASH or my post here is redundant!
The online manual reads:
Quote:
For the shell's purposes, a command which exits with a zero exit status has succeeded.
A non-zero exit status indicates failure.... When a command terminates on a fatal signal whose number is N, Bash uses the value 128+N as the exit status.
If a command is not found, the child process created to execute it returns a status of 127. If a command is found but is not executable, the return status is 126.
If a command fails because of an error during expansion or redirection, the exit status is greater than zero.
so a value of 255 would indicate a fatal error. A misuse of args would generate 1, or thats what happens with my testing.
The value 127 in bash refers to illegal command, i.e., when a command is entered that bash cannot figure out, it returns 127, and it means that your command did not enter the execution phase. The previous command you entered, $ echo $?, was obviously wrong, and bash cannot interpret it, so it returned that value.
BINGO I've cracked it. The exit code 255 means that the exit status is out of range. Return positives from the java instead of negative numbers. Test for this. BASH don't like negative returns.
Exit results must be in the range 0-255 not using 1, 2, 126-165, and 255. These have special meaning.
You should use 3 or 4 for an exit value as 1 is a general error, you could use that but 2 is misuse of shell builtins so use another return value.
SORRY! to UltimaGuy that was your link to the Advanced Bash site that helped me crack it! Credit where credits due!
I'm having the same problem as Andy@DP is having, I'm getting values from $? that don't mean anything (to me that is, no doubt the system knows exactly what they mean).
In the case of my java program, if I run it and it runs into problems, the value of $? is 255, no matter if I return -1, -2 or anything else.
And yes, I have checked the value of $? directly after running the java program.
To correct a mistake from my part: I stated somewhere that the $? always gave 255 when I executed my java program, this isn't true. Actually, when I return -1, the value of $? is 255, if I return -2, the value of $? is 254 and so on...
So I think I'll use positive integers instead.
Thank you very much to all people who participated in this thread!
Not a problem nephilim.
I like to try and help out whenever I can, I still consider myself to be a newbie in many areas but participating in forums helps broden my knowledge while helping others.
It's probably best to focus on using non-negative numbers are return codes. Conventionally a 0 is success and 1 is error. Some programs may use other numbers greater than 0 for specific error conditions.
The return code an unsigned 8 bit value - which is why you're seeing negative numbers wrap around. If you surf some man pages you'll see that exit codes are non-negative.....at least for man pages that list exit codes. The curl man page lists many in an "EXIT CODES" section. The bash man page talks about exit codes in several different places.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.