Converting JString array into char*[]

Bryan Ha kfh1_99@yahoo.com
Fri Aug 17 06:41:00 GMT 2001


Hello,

I am new to CNI and would appreciate if anybody could
help me out with this problem.

I am trying to pass down a String array from Java code
to the native code like this:

My aim is to convert String[] into char*[] which can
be used by the system call execve. Does this work ?
And is this the preferred way ?

Java part -Hello.java

public native int process(String[] arguments,String[]
env)

Native part

jint Hello::process(java::lang::String[] arguments,
java::lang::String[] environ)

char* args[arguments.length];
char* envp[environ.length];
int i=0;
int l1;
int l2;

for (i=0;i<arguments.length;i++) {
	jstring arg=arguments[i];
	jstring env=environ[i];

	l1=JvGetStringUTFLength(arg);
	l2=JvGetStringUFTLength(env);

	JvGetStringUTFRegion(arg,0,l1,args[i]);
	JvGetStringUTFRegion(env,0,l1,envp[i]);
}

execve(cmd,args,envp);

Any comments are much appreciated.

Many thanks,

Bryan


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie



More information about the Java mailing list