Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java and status codes.

Reply
Thread Tools

java and status codes.

 
 
horos11
Guest
Posts: n/a
 
      06-10-2009
All,

Much to my dismay, it doesn't look like the exit code with java
(System.exit()) is hooked up with the OS. ie - if I say:

public class samp
{
public static void main(String[] args)
{
System.exit(256);
}
}

compile and run this as in:

javac samp.java
java samp

and then check the error status from the shell, I get:

echo $? // prints '0'

why is this? Is there a way to get the sun JVM to set $? on failure?
Else, how do you know the program failed, from a shell standpoint?

Ed
 
Reply With Quote
 
 
 
 
Donkey Hottie
Guest
Posts: n/a
 
      06-11-2009
horos11 <(E-Mail Removed)> wrote in news:237af857-b09d-4881-bafe-
http://www.velocityreviews.com/forums/(E-Mail Removed):

> All,
>
> Much to my dismay, it doesn't look like the exit code with java
> (System.exit()) is hooked up with the OS. ie - if I say:
>
> public class samp
> {
> public static void main(String[] args)
> {
> System.exit(256);
> }
> }
>
> compile and run this as in:
>
> javac samp.java
> java samp
>
> and then check the error status from the shell, I get:
>
> echo $? // prints '0'
>
> why is this? Is there a way to get the sun JVM to set $? on failure?
> Else, how do you know the program failed, from a shell standpoint?
>
> Ed
>


I created a shell script

---------------------------
#!/bin/sh

exit 256
---------------------------

It also returns 0

exiting 255 returns 255

So it seems 255 is max return code in (linux). 256 becomes 0.





 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      06-11-2009
Donkey Hottie wrote:

> horos11 <(E-Mail Removed)> wrote in news:237af857-b09d-4881-bafe-
> (E-Mail Removed):
>
>> All,
>>
>> Much to my dismay, it doesn't look like the exit code with java
>> (System.exit()) is hooked up with the OS. ie - if I say:
>>
>> public class samp
>> {
>> public static void main(String[] args)
>> {
>> System.exit(256);
>> }
>> }
>>
>> compile and run this as in:
>>
>> javac samp.java
>> java samp
>>
>> and then check the error status from the shell, I get:
>>
>> echo $? // prints '0'
>>
>> why is this? Is there a way to get the sun JVM to set $? on failure?
>> Else, how do you know the program failed, from a shell standpoint?
>>
>> Ed
>>

>
> I created a shell script
>
> ---------------------------
> #!/bin/sh
>
> exit 256
> ---------------------------
>
> It also returns 0
>
> exiting 255 returns 255
>
> So it seems 255 is max return code in (linux). 256 becomes 0.


The UNIX/Linux world uses a 16 bit integer for the return from wait(). The lower
8 bits are the "status" and the upper 8 bits are - I forget. All that gets
passed back to the shell is the lower 8 status bits.

See man 3 exit and man 2 wait, the value returned up the stack by exit(status)
is status&0377.

--
Nigel Wade
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      06-11-2009
On Thu, 11 Jun 2009, Nigel Wade wrote:

> The UNIX/Linux world uses a 16 bit integer for the return from wait(). The lower
> 8 bits are the "status" and the upper 8 bits are - I forget.


Something like which signal killed the process? I forget too!

tom

--
Please! Undo clips before opening handle.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can I use more than one status condition name in imaplib.status() harryos Python 0 10-13-2010 01:37 PM
status info like rc.status Sven S. Ruby 2 12-11-2008 08:26 AM
Recommend a free 'Status Monitor' or 'Dashboard' to report overnight tasks status? Shug Java 13 12-15-2006 06:22 PM
Recommend a free 'Status Monitor' or 'Dashboard' to report overnight tasks status? Shug C++ 13 12-15-2006 06:22 PM
POST problem - IIS sc-win32-status:64; sc-status:400 saha ASP .Net 0 07-14-2005 07:10 AM



Advertisments