Reputation: 1723
If I am running external program(batch file) from java then, What I need to do:
if (process.exitValue() == 0) {//means executed successfully ???
Can't the return value be something else and batch executed successfully.
Is that the only way to check??
Upvotes: 2
Views: 514
Reputation: 24375
In many programs 0 is is success, negative numbers are errors and positive numbers are warnings. Of course this is just a convention and it all depends on what convention was followed. In most programming languages you can define an exit code for a program and that is what is picked up.
In Java System.exit(n)
In C main is defined as int main(int argc, char* argv[]) and the return from main is the return from the program.
Upvotes: 0
Reputation: 596
On Linux, your program can return any status you want. By convention 0 means success.
For example, if you execute a shell script, the return status will be the return status of the last command executed in your script.
Upvotes: 0
Reputation: 29619
The exit code of the batch process will be defined by that process but generally an exit code of 0
is defined as successful and a non zero value indicates that something went wrong. In your batch file you can set the return code by calling:
EXIT /B %ERROR_CODE%
%ERROR_CODE%
is the number that will be returned as the exit code.
Upvotes: 0
Reputation: 199205
You could read the output stream ( or the error stream ) and interpret it
Upvotes: 0
Reputation: 6087
I'm a bit confused by your wording, but by convention, [exitValue()
](http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html#exitValue()) returns 0
upon a successful execution. This is, as far as I know, the only way to check.
EDIT:
I suppose you could use [getErrorStream()
](http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html#getErrorStream()) - I assume it'll be blank if there are no errors in the process...
Upvotes: 1