The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enviornment Variable in B shell (I call it nested variable) princelinux Shell Programming and Scripting 4 07-01-2008 10:35 PM
Setting environment variable on a remote solaris machine using shell script eamani_sun Shell Programming and Scripting 1 05-30-2008 07:05 PM
Setting Environment Variable date d3ck_tm High Level Programming 6 11-08-2006 03:33 AM
Setting up Environment Variables rpandey Shell Programming and Scripting 6 06-06-2005 06:28 AM
setting environment variables ??? Gargamel UNIX for Dummies Questions & Answers 5 06-13-2002 08:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-17-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
Setting environment variable using JNI call

I have function declaration in Java and same function definition written in C programming language.. A JNI call from Java is made to a fuction...Function would set the environment variable { putenv(cEnvString1);} using C-built -in function ..and later return the encrypted string...

putenv is used to set the environment variable in C...Is there any alternate function to set the environment variable..? Looks like putenv is working here.
getenv function works well..


C function definition for a JNI call:-
-----------------------------------------
JNIEXPORT jstring JNICALL Java_gdm_schema_main_encryption_encryptStr
(JNIEnv *j_env, jobject j_obj)
{
char *cConnString = NULL ;


char *cEnvUserPasswd = NULL;

char cEnvString1[200]= {"FND_HIDDEN_USERPASS="};


/**
** If environment variable is not set
**/
/*
if (cEnvUserPasswd == NULL)
{
fprintf(stderr,"\nError in finding connect string info. exiting ...Shafi\n");
exit(-1);
}
*/

/**
** If Environment variable contains unencrypted login-password
** i.e. called directly from bin, return it .
**/
/*

if (strchr(cEnvUserPasswd , (int)'/') != NULL)
return convertToJavaString( j_env, cEnvUserPasswd ,strlen(cEnvUserPasswd));
else
{
cConnString = process_string ("INSTALL/install@fnd9i", "0", ENCRYPT);
return convertToJavaString( j_env, cConnString , strlen(cConnString));
}
*/
fprintf(stderr,"\nEncryption block.... ...\n");
cConnString = process_string ("INSTALL/install@fnd9i", "0", ENCRYPT);

putenv("FND_HIDDEN_USERPASS=NONE");
/* Prepare string for putenv function
sprintf(cEnvUserPasswd,"%s",cConnString);
*/
strcat(cEnvString1,cConnString);


/* Keep the Connect string and position in Environment */
putenv(cEnvString1);


fprintf(stderr,"\nAfter calling encryption %s.... ...\n",cEnvString1);

fprintf(stderr,"\nAfter calling encryption %s..%s..%d ...\n",j_env,cConnString,strlen(cConnString));

return convertToJavaString( j_env, cConnString , strlen(cConnString));

}

------------------------
Reply With Quote
Forum Sponsor
  #2  
Old 07-18-2008
Sivaswami's Avatar
Registered User
 

Join Date: Mar 2007
Location: India
Posts: 58
May I know what reason you are trying to set Environment variable from a Java Program ?
Reply With Quote
  #3  
Old 07-18-2008
Sivaswami's Avatar
Registered User
 

Join Date: Mar 2007
Location: India
Posts: 58
Normally Java programs should not be closely tied up with environment. if you want to set some values to be shared. you can use System Properties of Java
Reply With Quote
  #4  
Old 07-18-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
Code should be in C since function definition is written in C and declaration in Java...
Reply With Quote
  #5  
Old 07-18-2008
Sivaswami's Avatar
Registered User
 

Join Date: Mar 2007
Location: India
Posts: 58
There are 3 environment accessing techniques in these programs
1) C
2) JNI
3) Java
In C , you are changing the environment of the process which is launched. where as the shell, or other process is not aware of it. Even in unix, we use export command for
exporting few environment variables.
The best way is to use Java's System functionality.
Reply With Quote
  #6  
Old 07-18-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
Thanks ! How can we export a variable from C programme...
Reply With Quote
  #7  
Old 07-18-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
putenv()

See the manpage of putenv().
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0