By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

How can i keep an environment variable from C

P: 3
i used putenv to put variable, and worked ! But, ofcourse it is only valid while program is running.

How can i force to keep this varible value, even when the program terminates ? Any idea ?
Dec 15 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 2,398
Functions putenv (and setenv) are not part of Standard C despite being fairly common extensions. This means there is no portable way to alter environment variables. What is your run-time environment? Maybe somebody here is familiar with it and can tell an implementation-dependent method to do what you ask.
Dec 15 '10 #2

P: 3
Thanks for the reply Don.
My environment is for example:
APP=/opt/app and i want to replace this with for example APP=/opt/app2.
The problem is that I can replace this while the program is running, but, when it terminates, of course the variable value is gone, and then back to APP=/opt/app.
Dec 17 '10 #3

Expert 100+
P: 2,398
My point was that the details of how to write to an environment variable differ from one platform to another. Nobody can answer your question without knowing what platform you are running on. What operating system (and version), what compiler (C/C++, what vendor), did putenv come with your compiler or is it part of another library (what library), anything else that makes your platform unique.
Dec 17 '10 #4

P: 3
Oh, sorry ! My english suck a little bit.
#Debian GNU/Linux 5.0.7 (lenny)
#gcc version 4.3.2 (Debian 4.3.2-1.1)
Putenv is defined at stdlib.h !

Is this help Don ?
Dec 17 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.