home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8924 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  2.2 KB

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