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. Advertising

  2. horos11 <> wrote in news:237af857-b09d-4881-bafe-
    :

    > 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.
    Donkey Hottie, Jun 11, 2009
    #2
    1. Advertising

  3. horos11

    Nigel Wade Guest

    Donkey Hottie wrote:

    > horos11 <> wrote in news:237af857-b09d-4881-bafe-
    > :
    >
    >> 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
    Nigel Wade, Jun 11, 2009
    #3
  4. horos11

    Tom Anderson Guest

    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.
    Tom Anderson, Jun 11, 2009
    #4
    1. Advertising

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. Greg  --
    Replies:
    4
    Views:
    2,152
  2. JThomas
    Replies:
    2
    Views:
    4,473
    JThomas
    Jan 24, 2006
  3. Replies:
    2
    Views:
    2,818
    Malcolm
    Aug 20, 2005
  4. Allen
    Replies:
    1
    Views:
    641
    Mark Rae [MVP]
    Dec 3, 2007
  5. horos11

    java and status codes.

    horos11, Jun 10, 2009, in forum: Java
    Replies:
    1
    Views:
    283
    Arne Vajhøj
    Jun 11, 2009
Loading...

Share This Page