ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
As I understand it the whole java system.exit(x) method is designed for just that purpose. The quitting with a number lets a calling script know what has happened after it has called a program/other script.
I know no unix scripting but pseudo-code would look something like this.
(result is a variable to hold result of call to app)
result = call to application.
if result equals 0
application executed OK so do something
else if result equals -1
application failed so do something else
I think thats how to catch the system.exit() number. A unix scripter may give a proper code solution but thats something to work with.
Just did a little search and came up with the following. It may not be 100% correct but hopefully it will help you.
if ["`java -cp /home/myhome test /home/myhome test `" = "-1"]; then
echo "Error -1 happened";
if ["`java -cp /home/myhome test /home/myhome test `" = "-2"]; then
echo "Error -2 happened";
echo "No problems there!";
Note the ` (back quote - key left of 1). This means run the command and substitute the output (hopefully the system.exit output). Hope this helps, actually I hope it works!
You can check the return value of the program just completed in the shell script by checking the shell variable '$?'. For example , your program return any value between -1 to -9 depending upon the errors, you can check it IMMEDIATELY by checking the variable $?. It holds the value 0 if no value is returned and the program has executed successfully, and other values if the program returns it.
echo $? returns the value of the last completed program. So, you have to check for it immediately after you complete the java program. So, if you check it after your script is executed, you have the return value of your script.
Try executing your program, i.e, '$ java progname' and now type '$ echo $?' and you will get the return value. You can also try it with other commands such as ls.
Type '$ ls djfnf' and you will get -1
Type '$ jksnfkn' and you will get 255 (I don't remember).
So, try it and post the reply.
PS.. nephilim, I am happy to see that we both think alike, and also I have beat you in this!!!