Getting a return code from main
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Is there a way to get/save a return code
from a java program? I need to integrate it
with ESP, a scheduling program that runs on
the mainframe. I need to launch the
java program from within a Unix shell script
and get some type of return code to determine
if I should do other processing.
Any help would be greatly appreciated ...
from a java program? I need to integrate it
with ESP, a scheduling program that runs on
the mainframe. I need to launch the
java program from within a Unix shell script
and get some type of return code to determine
if I should do other processing.
Any help would be greatly appreciated ...
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
you write public static void main(){}
if you want to return a value write
public static "return type ie. int, String" main(){}
if you want to return a value write
public static "return type ie. int, String" main(){}
Ezra Exposito
Ranch Hand
Posts: 34
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I tried doing:
and got a java.lang.NoSuchMethodError exception.
and got a java.lang.NoSuchMethodError exception.
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This is not a Servlet question.
Moved from Servlets -> Java In General (Beginner)
Moved from Servlets -> Java In General (Beginner)
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Main has to return void. To exit with a non-zero status, use:
System.exit(int status);
System.exit(int status);
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You must use
for the main method.
To pass a return code to a UNIX shell do
System.exit(returnCode); as Dave said.
You should then be able to pick it up in a shell using the symbol $? "dollarquestionmark"
-Barry
[ October 25, 2002: Message edited by: Barry Gaunt ]
for the main method.
To pass a return code to a UNIX shell do
System.exit(returnCode); as Dave said.
You should then be able to pick it up in a shell using the symbol $? "dollarquestionmark"
-Barry
[ October 25, 2002: Message edited by: Barry Gaunt ]
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This is one question which I always like to ask. I tried with following code but didnt get anything on my console. How can I catch this integer from here to another program. can somebody help to give some example.
regards,
Arun
regards,
Arun
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
yeah . that could be a way .... using System.exit
as I dont know much about shell scripting... so I thought there is another solution
...if the main methods executes successfully ,its last line will also execute ... in the last line of your main method , perform some task (like renaming a file), then you can check in UNIX ... it may sound funny , but I guess it will serve your purpose
as I dont know much about shell scripting... so I thought there is another solution
...if the main methods executes successfully ,its last line will also execute ... in the last line of your main method , perform some task (like renaming a file), then you can check in UNIX ... it may sound funny , but I guess it will serve your purpose
arun mahajan
Ranch Hand
Posts: 305
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes bhart, perhaps that could be a way..but is there any other decent way of achieving same. I was wondering how I can send the response back to my another java file which is say servlet or something else or perhaps if I call a java program from VB application.
Any other idea?
Arun
Any other idea?
Arun
bharat nagpal
Ranch Hand
Posts: 76
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Arun if you need to call java program from servlets...thats easy if you want to instantiate a class from Servlet....
and if u need to call a java program from VB....for that you should use JAVA-COM bridge , you just have to write the WRAPPERS and you can control the tasks(of java application) from VB.I have done it using JAVAREG...
but for simple purpose ... System.exit is good way, as explained by others. although I've never used this...
and if u need to call a java program from VB....for that you should use JAVA-COM bridge , you just have to write the WRAPPERS and you can control the tasks(of java application) from VB.I have done it using JAVAREG...
but for simple purpose ... System.exit is good way, as explained by others. although I've never used this...
Dave Landers
Ranch Hand
Posts: 401
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
As we've said, you use System.exit(int) to exit a java program with some "exit status code". Also note that if your program exits because the main thread throws an exception, the VM will exit with a non-zero status. A zero exit status usually means "OK", and non-zero means "BAD".
But how you use this value depends on the environment you are running in.
In Unix, you can get the exit status of the most recent command using the shell variable $?.
If you run the program from Java with Runtime.exec(), then you can find the exit status form Process.exitValue().
I have no idea how you do this if you invoke a program from VB or DOS or etc....
But how you use this value depends on the environment you are running in.
In Unix, you can get the exit status of the most recent command using the shell variable $?.
If you run the program from Java with Runtime.exec(), then you can find the exit status form Process.exitValue().
I have no idea how you do this if you invoke a program from VB or DOS or etc....
arun mahajan
Ranch Hand
Posts: 305
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks bharat1 for giving me a new path called "JAVA-COM bridge" can u give me more light on it..where can i find more literature. BTW, how to write my own Wrapper class is also a issue at my end. I am not an expert. can you please help.
Yes Dave. I am running a program from VB and would like to know the status of exit of this java program. What I am try to find out if there are means available if I go crossplatform. BTW, I am on windows OS not on UNIX.
regards,
Arun
Yes Dave. I am running a program from VB and would like to know the status of exit of this java program. What I am try to find out if there are means available if I go crossplatform. BTW, I am on windows OS not on UNIX.
regards,
Arun
Dave Landers
Ranch Hand
Posts: 401
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Cross-platform and VB? Not likely. At least not the way I define cross-platform (to mean a program that can be run on several different kinds of platforms, usually including at least unix and windows and probably mac and maybe others).
Ezra Exposito
Ranch Hand
Posts: 34
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks for the info everyone. You
have been extremely helpfull as usual.
have been extremely helpfull as usual.
arun mahajan
Ranch Hand
Posts: 305
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks Dave. I used the wrong term. You're right.
Arun
Arun
| New rule: no elephants at the chess tournament. Tiny ads are still okay. Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







