Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i create, read & write environment variables

Status
Not open for further replies.

sixtoedsloth

IS-IT--Management
Jan 1, 2002
118
GB
HI,

on sco openserver 5.0.5 :-

i have a database language that cannot use sockets but needs to communicate with a device that uses sockets..

SO. i have a c program that talks to the device and writes
a text file, which the db language then reads in.

which works.... but sometimes its too slow. so i wondered if i can use environment variables to communicate the data
which would stop me having to go to disk and speed thing up. but i cant find anything about writing an environment variable, so if anyone can help out or sugest a better way
of doing it i would be grateful!


Regards,

Russ
 
I don't know about creating an environment variable programmatically....

/* GETENV.C: This program uses getenv to retrieve
* the LIB environment variable and then uses
* _putenv to change it to a new value.
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
char *libvar;

/* Get the value of the LIB environment variable. */
libvar = getenv( &quot;LIB&quot; );

if( libvar != NULL )
printf( &quot;Original LIB variable is: %s\n&quot;, libvar );

/* Attempt to change path. Note that this only affects the environment
* variable of the current process. The command processor's environment
* is not changed.
*/
_putenv( &quot;LIB=c:\\mylib;c:\\yourlib&quot; );

/* Get new value. */
libvar = getenv( &quot;LIB&quot; );

if( libvar != NULL )
printf( &quot;New LIB variable is: %s\n&quot;, libvar );
}

Output
Original LIB variable is: C:\progra~1\devstu~1\vc\lib
New LIB variable is: c:\mylib;c:\yourlib

 
cheers,
it seems that under unix, the environment is passed to my
program, but any changes are discarded when i return

is there any way of comunicating between programs?

russ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top