cancel
Showing results for 
Search instead for 
Did you mean: 

how to get exit code from C code when calling java method via JNI?

Former Member
0 Kudos

Hi, All

in my project, i need to call a java method from C code using JNI, yet I do

not know how to

retrieve the exit code of java program. the java code is like below

....

public static void main(....)

{

.....

if(error){

System.exit(-77);// the exit code is -77

....

}

and the JNI c code may like below

.....

/* Invoke main method. */

(*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs);

//here I want to retrieve the exit code from java to check if there is an

error

...

--

any suggestions? thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

anyone knows?

former_member182372
Active Contributor
0 Kudos

Hi Liang Zhang,

In your C code add:


void (JNICALL y_exit)(jint code) {
/...
}

and when you are initialazing JVM options add:


JavaVMOption options[...];

options[...].optionString = "exit";
options[...].extraInfo    = y_exit;

See http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Rashchynski, Thank you very very much

i modified my code followed your sample, and it works well now.

former_member182372
Active Contributor
0 Kudos

Hi,

In case the problem is solved, please, close the thread.

Best regards, Maksim Rashchysnki.