java and status codes.

H

horos11

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
 
D

Donkey Hottie

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

Nigel Wade

Donkey said:
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.
 
T

Tom Anderson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top