home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!decwrl!access.usask.ca!ccu.umanitoba.ca!ciit85.ciit.nrc.ca!brandonu.ca!dueck
- Newsgroups: comp.os.msdos.programmer
- Subject: Re: How can you set an environment variable in a program?
- Message-ID: <1992Aug31.144636.2186@brandonu.ca>
- From: dueck@brandonu.ca
- Date: 31 Aug 92 14:46:35 CST
- References: <1345@rand.mel.cocam.oz.au> <690@aardvark.Rain.COM> <1992Aug24.143641.1@camins.camosun.bc.ca>
- Organization: Brandon University, Brandon, Manitoba, Canada
- Lines: 49
-
- In article <1992Aug24.143641.1@camins.camosun.bc.ca>, morley@camins.camosun.bc.ca writes:
- > In article <690@aardvark.Rain.COM>, tyrant@Aardvark.Rain.COM (Rex Goode) writes:
- >> dmh@superb (Daniel Hermans) writes:
- >>
- >>>hi,
- >>>i am using turbo c v2.0 to generate a temporary file name,
- >>>place some data in the temporary file and then close the file. the temp
- >>>file is then to be used on the command line of another program. both
- >>>programs are called within a batch file something like:
- >>
- >>>@echo off
- >>
- >>>program1
- >>>program2 < %tempfile%
- >>
- >>> system("set tempfile=tmpx.$$$");
- >>
- >>>i tried using system(command) as above but the variable is not set when the
- >>>program exits probably because system starts a new command.com shell each
- >>>time
- >>
- >> Absolutely right about the new command.com, with its own environment. That
- >> is what happens when you use system(). Try setenv(),
- >>
- >> setenv("TEMPFILE=TMPX.$$$);
- >>
- >
- > Sorry, but setenv() also only modifies the "local" environment. It will not
- > change it "permanently".
- >
- > MARK
- > morley@camins.camosun.bc.ca
- >
-
- The best way I have found to set a global environment variable is to use
- interrupt 2e, the back door to the command interpreter. Construct a string
- with a command like "set x=y\r" and pass it to INT 2E via DS:DX.
-
- Since 2E destroys all regs except CS:IP, you must restore the SS:SP from
- a place addressable from CS, and restore DS from the stack.
-
- If you have set a global environment variable and wish to access it
- subsequently using getenv(), free the program's local environment and
- point the environment segment in the PSP at its parent's environment.
- If you do this, set the environment segment in the PSP to zero before
- exiting, or program cleanup will attempt to delete the master environment.
-
- Gery Dueck
- dueck@brandonu.ca
-