home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8964 < prev    next >
Encoding:
Text File  |  1992-09-01  |  3.7 KB  |  90 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!gatech!taco!dspascha
  3. From: dspascha@eos.ncsu.edu (DAVID SCOTT PASCHAL)
  4. Subject: Re: How can you set an environment variable in a program?
  5. Message-ID: <1992Sep1.213605.29103@ncsu.edu>
  6. Originator: dspascha@c00089-100lez.eos.ncsu.edu
  7. Lines: 76
  8. Sender: news@ncsu.edu (USENET News System)
  9. Reply-To: dspascha@eos.ncsu.edu (DAVID SCOTT PASCHAL)
  10. Organization: North Carolina State University, Project Eos
  11. References: <1345@rand.mel.cocam.oz.au> <690@aardvark.Rain.COM> <1992Aug24.143641.1@camins.camosun.bc.ca> <1992Aug31.144636.2186@brandonu.ca>
  12. Date: Tue, 1 Sep 1992 21:36:05 GMT
  13.  
  14.  
  15. In article <1992Aug31.144636.2186@brandonu.ca>, dueck@brandonu.ca writes:
  16. |> Path: taco!gatech!swrinde!sdd.hp.com!decwrl!access.usask.ca!ccu.umanitoba.ca!ciit85.ciit.nrc.ca!brandonu.ca!dueck
  17. |> From: dueck@brandonu.ca
  18. |> Newsgroups: comp.os.msdos.programmer
  19. |> Subject: Re: How can you set an environment variable in a program?
  20. |> Message-ID: <1992Aug31.144636.2186@brandonu.ca>
  21. |> Date: Mon, 31 Aug 92 16:46:35 GMT+5:00
  22. |> References: <1345@rand.mel.cocam.oz.au> <690@aardvark.Rain.COM> <1992Aug24.143641.1@camins.camosun.bc.ca>
  23. |> Organization: Brandon University, Brandon, Manitoba, Canada
  24. |> Lines: 49
  25. |> 
  26. |> In article <1992Aug24.143641.1@camins.camosun.bc.ca>, morley@camins.camosun.bc.ca writes:
  27. |> > In article <690@aardvark.Rain.COM>, tyrant@Aardvark.Rain.COM (Rex Goode) writes:
  28. |> >> dmh@superb (Daniel Hermans) writes:
  29. |> >> 
  30. |> >>>hi,
  31. |> >>>i am using turbo c v2.0 to generate a temporary file name,
  32. |> >>>place some data in the temporary file and then close the file. the temp
  33. |> >>>file is then to be used on the command line of another program. both
  34. |> >>>programs are called within a batch file something like:
  35. |> >> 
  36. |> >>>@echo off
  37. |> >> 
  38. |> >>>program1
  39. |> >>>program2 < %tempfile%
  40. |> >> 
  41. |> >>>   system("set tempfile=tmpx.$$$");
  42. |> >> 
  43. |> >>>i tried using system(command) as above but the variable is not set when the
  44. |> >>>program exits probably because system starts a new command.com shell each
  45. |> >>>time
  46. |> >> 
  47. |> >> Absolutely right about the new command.com, with its own environment. That
  48. |> >> is what happens when you use system(). Try setenv(),
  49. |> >> 
  50. |> >> setenv("TEMPFILE=TMPX.$$$);
  51. |> >> 
  52. |> > 
  53. |> > Sorry, but setenv() also only modifies the "local" environment.  It will not
  54. |> > change it "permanently".
  55. |> > 
  56. |> > MARK
  57. |> > morley@camins.camosun.bc.ca
  58. |> > 
  59. |> 
  60. |> The best way I have found to set a global environment variable is to use 
  61. |> interrupt 2e, the back door to the command interpreter. Construct a string 
  62. |> with a command like "set x=y\r" and pass it to INT 2E via DS:DX. 
  63. |> 
  64. |> Since 2E destroys all regs except CS:IP, you must restore the SS:SP from
  65. |> a place addressable from CS, and restore DS from the stack. 
  66. |> 
  67. |> If you have set a global environment variable and wish to access it
  68. |> subsequently using getenv(), free the program's local environment and
  69. |> point the environment segment in the PSP at its parent's environment.
  70. |> If you do this, set the environment segment in the PSP to zero before
  71. |> exiting, or program cleanup will attempt to delete the master environment.
  72. |> 
  73. |> Gery Dueck
  74. |> dueck@brandonu.ca
  75. |> 
  76.  
  77. Hi.  First of all, don't you pass the string in DS:SI?  And you also have to
  78. pass the length of the string (not counting the return) in the first byte.
  79.  
  80. Also, I have read (and
  81. have found from experience) that INT 2E is extremely unpredictable, unstable,
  82. and unportable.  You <might> be OK just using it to modify the master
  83. environment, but even so, not all DOS shells support it.  Besides, if 'program1'
  84. weren't run from the primary shell (i.e. if it were run in a secondary copy of
  85. COMMAND.COM), then %tempfile% in the line "program2 <%tempfile%" would not be
  86. defined.
  87.  
  88. Tschuess,
  89. David Paschal
  90.