Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Values of process.exitValue() in JAVA

Tags:

java

process

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

like image 348
mustafa Avatar asked Nov 01 '22 06:11

mustafa


1 Answers

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".

like image 109
Jon Skeet Avatar answered Nov 15 '22 04:11

Jon Skeet