Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman) Newsgroups: comp.sys.ibm.pc Subject: Re: Environment settings from a C program Message-ID: <128@fxgrp.UUCP> Date: Thu, 22-Oct-87 13:55:03 EST Article-I.D.: fxgrp.128 Posted: Thu Oct 22 13:55:03 1987 Date-Received: Sun, 25-Oct-87 01:45:36 EST References: <700@hsi.UUCP> <2400@bcsaic.UUCP> <2434@bcsaic.UUCP> Reply-To: ljz@fxgrp.UUCP (Lloyd Zusman) Organization: FX Development Group, Inc., Mountain View, CA Lines: 70 Keywords: ms-dos environ putenv getenv turboc Summary: Some caveats about int 2Eh With regard to using int 2Eh to cause the top-level command interpreter to execute a command line ... Yes, this can be used to set an environment variable in the top-level command interpreter, but there are some caveats that may or may not be important: 1) This is an undocumented DOS call, meaning that it may go away or change. 2) Once you use it to set an environment variable in the top-level command interpreter, the varible DOES NOT propagate down to all the children of this top-level interpreter. In other words, assume I have booted up my PC and I'm sitting at the command prompt: C> I type SET and I get a list of environment variables containing the line FOO=BAR This means that there is a variable named FOO in my environment with the value BAR. Now, suppose I have written a C program that contains the following code fragment ... extern char *getenv(); char *ep = getenv("FOO"); printf("FOO=%s\n", ep ? ep : ""); int1e("SET FOO=QUACK"); ep = getenv("FOO"); printf("FOO=%s\n", ep ? ep : ""); Assume that the int1e() function passes its string argument to int 1Eh properly. The output of this program fragment will be FOO=BAR FOO=BAR It will NOT be FOO=BAR FOO=QUACK as you might hope. But after the program returns control to DOS, the next time you type SET, you will see the line FOO=QUACK in your environment. If you insert the following call after the int1e() call in the above program putenv("FOO=QUACK") then you will see the value of the variable FOO change during the course of running the program. To make it worse, suppose that from DOS I run a program that causes a subshell to run, and within this subshell, the above program is run (the version with the putenv()). What will happen is that the top level environment will be changed (via the int 1Eh), the environment in effect while the program is running will be changed (via the putenv() call), but the environments for all processes inbetween these will stay the same. If this sort of thing is what you want, then int 1Eh is useful. Otherwise, be careful. 3) I have had applications hang when making use of int 1Eh. I think it might have to do with the amount of space taken up by TSR ("Terminate and Stay Resident") programs, the version of DOS that's being run, etc. Be careful.