java and status codes.

Discussion in 'Java' started by horos11, Jun 10, 2009.

  1. horos11

    horos11 Guest

    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
     
    horos11, Jun 10, 2009
    #1
    1. Advertisements

  2. 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
     
    Arne Vajhøj, Jun 11, 2009
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish

    constants for http status codes

    Andy Fish, Mar 3, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    4,170
    Juan T. Llibre
    Mar 4, 2005
  2. =?Utf-8?B?RGFuaWVsIEtvcHA=?=

    Custom error pages for HTTP errors with IIS status codes

    =?Utf-8?B?RGFuaWVsIEtvcHA=?=, Jul 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    597
    =?Utf-8?B?RGFuaWVsIEtvcHA=?=
    Jul 12, 2005
  3. Greg  --
    Replies:
    4
    Views:
    2,813
  4. JThomas
    Replies:
    2
    Views:
    4,760
    JThomas
    Jan 24, 2006
  5. Replies:
    2
    Views:
    3,544
    Malcolm
    Aug 20, 2005
  6. Allen
    Replies:
    1
    Views:
    822
    Mark Rae [MVP]
    Dec 3, 2007
  7. horos11

    java and status codes.

    horos11, Jun 10, 2009, in forum: Java
    Replies:
    3
    Views:
    726
    Tom Anderson
    Jun 11, 2009
  8. Oxnard

    http status codes and javascript

    Oxnard, Oct 23, 2004, in forum: Javascript
    Replies:
    3
    Views:
    270
    Martin Honnen
    Oct 24, 2004
Loading...