home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!swrinde!mips!mips!munnari.oz.au!deakin.OZ.AU!rand!superb!dmh
- From: dmh@superb (Daniel Hermans)
- Newsgroups: comp.os.msdos.programmer
- Subject: How can you set an environment variable in a program?
- Summary: can you set an env variable?
- Keywords: variable, C
- Message-ID: <1345@rand.mel.cocam.oz.au>
- Date: 22 Aug 92 03:07:06 GMT
- Sender: usenet@rand.mel.cocam.oz.au
- Lines: 38
- X-Newsreader: Tin 1.1 PL4
-
- 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%
-
- i need a way to tell the batch file the name of the tempfile that has been
- created, so that it can be used by the second program on it's command line.
-
- the only way i can see to do this would be to set an environment variable
- to the temp file name within program 1 for use by program 2:
- program1:
- generate temp file
- write to temp file
- close temp file
- system("set tempfile=tmpx.$$$");
-
- program2:
- use tmpx.$$$ for whatever.
-
- the name also needs to be unique so that multiple network users can create
- their own temp files when they all start in the same directory. i am
- using mktemp to generate the temp file name.
-
- 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
-
- any ideas ?
-
- --
- Daniel Hermans (dmh@superb.mel.cocam.oz.au)
- Co-Cam Computer Group, Melbourne, OZ (Phone : (613) 412-3341)
-