Sticky IBM C programming problems (summary of replies)

Conor P. Cahill cpcahil at virtech.uucp
Sat Mar 3 00:15:01 AEST 1990


In article <9003012109.AA07700 at ei.ecn.purdue.edu> tlmfe at EE.ECN.PURDUE.EDU (Mark B Strong) writes:
>
>Quick question:  Why won't an environmental variable I change within
>a C program stay after the program is terminated?  Setenv() doesn't seem
>to work?  

First of all, this isn't a C questions it is an OS question so I have forwarded
followups to comp.sys.ibm.pc

The answer is that a programs environmental variables are stored in that
program's data space is are lost when the program exits.  The only thing
special about environment variables is that there exists a convention for
passing that portion of your data space to all child processes, but you cannot
use it to change the data space of a parent process (which is what you are
apparently trying to do).

Of course, your program could pass the environment variable changes back
through a file descriptor (say stdout) and the parent program could 
make these changes in it's environment.  But you will have to modify both
programs to do this.

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list