Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!sri-unix!sri-spam!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman) Newsgroups: comp.sys.ibm.pc Subject: Re: Environment settings from a C program Message-ID: <114@fxgrp.UUCP> Date: Sun, 11-Oct-87 16:16:50 EDT Article-I.D.: fxgrp.114 Posted: Sun Oct 11 16:16:50 1987 Date-Received: Mon, 12-Oct-87 23:49:55 EDT References: <700@hsi.UUCP> Reply-To: ljz@fxgrp.UUCP (Lloyd Zusman) Organization: FX Development Group, Inc., Mountain View, CA Lines: 29 Keywords: ms-dos environ putenv getenv turboc Summary: Can't change DOS environment from within a running program In article <700@hsi.UUCP> mark@hsi.UUCP (Mark Sicignano) writes: >I am trying to change an environment variable from within >a Turbo-C program. Turbo-C provides a function, putenv() >which will make changes to, add, or delete environment, >but any changes are made to the environment within the program, >and for child processes. > >I need for these changes to remain. Is it possible? Sorry, but what you want to do isn't possible. DOS (be it MSDOS or PCDOS) is written such that no running program can change the environment of its parent. In case you need more explanation, consider this: When you are at the command level of DOS (i.e., when you are entering commands at the terminal), you are actually in a running program. When you run a C program (or whatever), DOS causes the program running at the command level to suspend, and it starts up another program running as a "child" program. This child is somewhat akin to a subprogram. So, using this terminology, the DOS command processor is a "parent" to your C program. Every time DOS starts up a child, it copies the parent's environment into a new area and that becomes the child's environent. Hence, any changes you make to the child's environment have no effect on the parent's environment. The main use of putenv() is so that your C program can start its own child process and pass altered or new values of its environment down to it. This would be done by calling putenv() and then calling one of the spawn() functions. Lloyd Zusman ...!ames!fxgrp!ljz