Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!bria!mike From: mike@bria.UUCP (mike.stefanik) Newsgroups: comp.lang.c Subject: Re: DOS Environment Variables Message-ID: <259@bria.UUCP> Date: 6 May 91 21:19:22 GMT References: <91125.051531AURPS@ASUACAD.BITNET> Reply-To: uunet!bria!mike Organization: MGI Group International, Los Angeles, CA Lines: 31 In an article, AURPS@ASUACAD.BITNET writes: >Does anyone know how to permanently change a DOS environment variable from >within an executing program? PUTENV() changes/creates a variable but it >is only in effect while the program is running. As soon as I go back to >DOS, the environment is restored to its original variables. I'm using >Turbo C. The problem that you are running into is that a child process (and I use the term "process" loosely insofar as DOS is concerned) cannot change the environment of it's parent. Of course, you can allways go hunting through memory, but that wouldn't be portable, would it? :-) Here is the situation that you have visually: +---------------+ | COMMAND.COM | (has the original copy of the environment) +---------------+ | +---------------+ | PROGRAM.EXE | (has a copy of command.com's environment) +---------------+ So, when command.com created the child, it gave it a *copy* of the environment table. Changes that are made, are made to the copy of the table, not the original. When the child dies, so goes the table as well. -- Michael Stefanik, MGI Inc, Los Angeles | Opinions stated are never realistic Title of the week: Systems Engineer | UUCP: ...!uunet!bria!mike ------------------------------------------------------------------------------- If MS-DOS didn't exist, who would UNIX programmers have to make fun of?