mustafa
mustafa

Reputation: 109

Values of process.exitValue() in JAVA

This question is about the values of process.exitValue().

If process.exitValue()=0 its ok, if it's -1 something is wrong, but if it's something else, what does it mean? For instance i am taking 6. That is the code i use:

Process process = Runtime.getRuntime().exec(command);
process.waitFor();  
Integer result = process.exitValue();

Edit: if process hangs, than process.exitValue() = 6

Upvotes: 8

Views: 23410

Answers (2)

daark
daark

Reputation: 326

it depends entirely on what the command is doing see the documentation http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html#exitValue()

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500575

That's up to the process in question. Even the "0 means success" is a convention more than anything else - although it's a very common one.

In general I would assume that any non-zero value is an error of some description; look at the documentation for whatever process you're executing for the meaning of specific exit values. If you don't know as the developer what process you're executing (e.g. it's user-specified) then there's no general way of interpreting a non-zero exit code other than "failure".

Upvotes: 4

Related Questions