Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit status running java classpath in a unix shell script

Status
Not open for further replies.

mmcds

MIS
Jul 5, 2007
28
US
I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.

notifycode=$?
echo $notifycode

I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.
 
During my testing it will error with java.io.FileNotFoundException error
but do you know that it has a non zero (should be 2 for File Not Found) exit status?.

Ceci n'est pas une signature
Columb Healy
 
No I am not sure of what the exit status of that error is. How can I find out exactly?

Also, after that error example I gave, there are plenty of lines that don't show any errors, for example like the lines below.

at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:129)

So I am wondering if since my error happens before lines like the example above, the exit status gets overridden with the most recent exit status of the last command?
 
So I am wondering if since my error happens before lines like the example above, the exit status gets overridden with the most recent exit status of the last command?
Almost certainly



When testing I assume that you run the command from the command prompt. To check the return try
Code:
echo $?

Ceci n'est pas une signature
Columb Healy
 
I ran the echo $? and sure enough it shows 0 for the exit status. Is there any way to capture the error exit status that could occur anytime during processing like for my FileNotFound Exception error? That is what I am trying to accomplish.
 
I don't know enough java but something like
Code:
ERROR_STORE=0
java.command.1 || ERROR_STORE=$?
java.command.2 || ERROR_STORE=$?
java.command.3 || ERROR_STORE=$?
java.command.4 || ERROR_STORE=$?
echo $ERROR_STORE
may be posible

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top