Setting environment from inside a pg.
Jonathan R. Herr
herrj at valnet.UUCP
Tue Nov 27 23:32:43 AEST 1990
gangwani at andromeda.rutgers.edu.rutgers.edu (Sunil Gangwani) writes:
>
> Hi,
>
> With the system() function call a new shell is executed in
> DOS or UNIX. I would like the set an environment variable from
> inside a program so that the variable exists when I exit the
> program??
>
> Ex. in DOS
>
> system("set var=Hello");
>
> The above will not work because a new command.com is executed
> and exited immediately. How can I overcome this simple problem??
Well, you don't say what C you're using. But, there is a way to set
environment variables in Turbo C 2.0 by use of the putenv(const char *name)
command. It is also availble on Unix systems according to the
reference guide. Something like this might work:
/* ========================================== */
#include <stdlib.h>
putenv("set var=Hello");
/* ========================================== */
My syntax may be off base. I'm not super-experienced in C like some
of these folk. I only know this much as I've been using getenv() to access
some environment variables for a program I've been writing for Waffle
BBS in which I have to locate a definition file that is defined as an
environment variable and I saw the reference to putenv().
> Please respond directly to gangwani at andromeda.rutgers.edu because
> due to heavy traffic our facility removes USENET stuff every two
> days...
I'll forward it to you.
> Sunil Gangwani
Jon Herr
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|Jonathan R. Herr (aka Jon) | herrj at silver.ucs.indiana.edu |
| | herrj at valnet.UUCP |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list