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
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      06-10-2009
Steven Simpson wrote:
> horos11 wrote:
>> public class samp
>> {
>> public static void main(String[] args)
>> {
>> System.exit(256);
>> }
>> }
>>
>> [...] and then check the error status from the shell, I get:
>>
>> echo $? // prints '0'

>
> Try some other values. For exit(x), I seem to be getting (x & 0xff).


That makes sense.

It is obviously a wrapper around the stdlib exit call.

And the C standard says:

If the value of status is zero or
EXIT_SUCCESS, an implementation-defined form of the status successful
termination is
returned. If the value of status is EXIT_FAILURE, an
implementation-defined form
of the status unsuccessful termination is returned. Otherwise the status
returned is
implementation-defined.

And the Unix specification say:

The value of status may be 0, EXIT_SUCCESS, EXIT_FAILURE, [CX] [Option
Start] or any other value, though only the least significant 8 bits
(that is, status & 0377) shall be available to a waiting parent process.

So assuming it is on Unix then this makes sense.

Arne
 
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