Home » Developer & Programmer » Precompilers, OCI & OCCI » setenv
setenv [message #93936] Wed, 30 April 2003 01:22 Go to next message
Norvin
Messages: 22
Registered: July 2001
Junior Member
i have a code like this:

sprintf( command, "setenv ORACLE_UID norvin" );
ret = system( command );
if ( ret ){
exit( 1 );
}
sprintf( command, "setenv ORACLE_PID delarosa" );
ret = system( command );
if ( ret ){
exit( 2 );
}
strcpy( name, getenv("ORACLE_UID") );
strcpy( passwd, getenv("ORACLE_PID") );
printf( "after setenv name [[%s]], passwd [[%s]]n", name, passwd );

when i check the printed value for ORACLE_UID & PID,
it show nothing.

cant I use setenv to assign environment variable inside a pro c programs?

if I still want to achieve this, how can I do that?

Thanks,
Norvin
Re: setenv [message #93987 is a reply to message #93936] Wed, 02 July 2003 02:31 Go to previous message
Matt Robinson
Messages: 3
Registered: July 2003
Junior Member
Hi.

The reason ORACLE_UID and ORACLE_PID are blank is because the system() function actually spawns another sub-environment to perform the specified task (in this case the setenv command). This sub-environment only lasts as long as the system() function and setenv only affects the environment it is running in, so the changes you make to that environment are lost and do not affect the program's environment.

Use the setenv() function instead of system - BUT BEWARE - you must use a global C variable to pass the string! The variable must be permanent or once it's contents are lost, your environment loses the setting.

eg.,

#include .....

char uid_env[[128]];

.
.
.

sprintf( uid_env, "ORACLE_UID=%s", name );
setenv( uid_env );

.
.
.

Regards,
Matt.
Previous Topic: Connect Error using PRO*C Code
Next Topic: Connect Error using PRO*C Code
Goto Forum:
  


Current Time: Sun May 26 21:21:15 CDT 2024