How can I set Env. variable from C.
I tryed to use system (str) but it did not change any of
my Env. variable.
Thanks.
Igor
It's definitely in the comp.unix.questions FAQ, which is on www.faqs.org.
--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
>Hi All
>How can I set Env. variable from C. I tryed to use system (str) but
>it did not change any of my Env. variable.
Hi there,
Most Unix systems implement either setenv() or putenv() as library
functions. Try doing 'man putenv' or 'man setenv', and see what turns
up. That's the usual mechanism for setting things in the current
process's environment (and, of course, thereby in the environment of
all your child processes).
Be aware, of course, that 'setenv' is usually also the name of a shell
command, so make sure you're looking at the appropriate manual page.
Cheers,
-M
--
Michael J. Fromberger Software Engineer, Thayer School of Engineering
sting <at> linguist.dartmouth.edu http://www.dartmouth.edu/~sting/
OfUb/Q/gvcIAtVDQ7kbZelrae4GIXJT8mmn38wXEpdUjthIOaDBPen8LcEij9zNFJzRNoe0W
The church is near, but the way is icy;
The tavern is far, but I will walk carefully. -- Ukrainian proverb
system("vriablename=value");
"Igor" <i.sok...@geac.com> wrote in message
news:392abf4f...@news.ca.geac.com...
> Hi All
>
> How can I set Env. variable from C.
> I tryed to use system (str) but it did not change any of
> my Env. variable.
>
> Thanks.
>
> Igor
>
This spawns a sub-shell which goes to great lengths for setting up PATHs
etc,
then does the command above, then quietly dies, whithout much of a trace in
the parent.
The question to ask is "What is it needed for?"
As has been pointed out before, there is no way a process can set an
environment variable of the parent.
However, it may be necessary for a process to set a variable for itself
(although there are more efficient ways of passing data around). Most
importantly, though, is to pass settings on to children (as e.g. login(1)
does with LOGNAME, HOME etc. before spawning a shell). For this purpose
exists putenv(3).
#include <stdlib.h>
int putenv(const char *string);
In any case, this belongs to comp.lang.c (F'up).
Regards,
--
Michael Sternberg, Dipl. Phys. | Uni-GH Paderborn
http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
phone: +49-(0)5251-60-2329 fax: -3435 | 33098 Paderborn, Germany
"Who disturrrbs me at this time?" << Zaphod Beeblebrox IV >> <*>
The simple way, of course, does you absolutely no good.
System() runs the shell as a child. That shell sets its
environment variable, then exits. Variable gone. Oops.
So sorry. You can't set a variable in your parent, no
matter how hard you try.