DOS Environment Variables

mike.stefanik mike at bria.UUCP
Tue May 7 07:19:22 AEST 1991


In an article, AURPS at 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?



More information about the Comp.lang.c mailing list