LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2003, 05:12 AM   #16
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30

Another test with odd results. command ls with fake args -nehf then echo $? returned 1.

Tried a command that didn't exist (lsd) and returned 127.

Tried real command (ls again) with above args and got 1.

Last edited by Andy@DP; 08-25-2003 at 05:14 AM.
 
Old 08-25-2003, 05:20 AM   #17
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
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.
 
Old 08-25-2003, 05:23 AM   #18
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
No, it returned correctly.

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.

Why don't you take a look at Advanced Bash Scripting Guide for further doubts.

I started bash from it, and it is a good starting point. There are pdf files also from www.gnu.org , but you have to search.
 
Old 08-25-2003, 05:26 AM   #19
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
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!

Last edited by Andy@DP; 08-25-2003 at 05:32 AM.
 
Old 08-25-2003, 05:27 AM   #20
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Original Poster
Rep: Reputation: 30
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.
 
Old 08-25-2003, 05:29 AM   #21
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
Read my above post that i entered at the same time you entered yours!

Last edited by Andy@DP; 08-25-2003 at 05:31 AM.
 
Old 08-25-2003, 05:35 AM   #22
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Original Poster
Rep: Reputation: 30
OK, it works now!

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!
 
Old 08-25-2003, 05:38 AM   #23
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
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.
 
Old 08-25-2003, 05:40 AM   #24
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Any how, Andy@DP , you have solved the problem when I browsing through the software forum, but I hope I'll solve it the next time. Let's see ...
 
Old 08-25-2003, 05:45 AM   #25
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
So long as one of us solves the problem (or any other member for that matter) then I'll be a happy bunny !
 
Old 10-22-2003, 10:51 AM   #26
Geekslap
LQ Newbie
 
Registered: Oct 2003
Distribution: RH9
Posts: 1

Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameters to network modules muru Linux - Networking 4 10-21-2005 10:44 AM
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 11:44 AM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 06:41 AM
passing parameters to functions in shell script kushalkoolwal Programming 1 09-28-2005 02:40 PM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 09:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration