Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!cica!iuvax!valnet!herrj From: herrj@valnet.UUCP (Jonathan R. Herr) Newsgroups: comp.lang.c Subject: Re: Setting environment from inside a pg. Keywords: C, environment, DOS Message-ID: <9ooaT1w163w@valnet> Date: 27 Nov 90 12:32:43 GMT References: Organization: Valley BBS Network Lines: 52 Disclaimer: Author responsible for contents gangwani@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 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@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@silver.ucs.indiana.edu | | | herrj@valnet.UUCP | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~