Date: Tue, 9 Jun 1998 12:53:02 +0200 From: Hans-Bernhard Broeker Message-Id: <199806091053.MAA27086@acp3bf.physik.rwth-aachen.de> To: RUHLED AT prodigy DOT net (DAVID G RUHLE) Cc: djgpp AT delorie DOT com Subject: Re: setting environment variables Newsgroups: comp.os.msdos.djgpp Organization: RWTH Aachen, III. physikalisches Institut B Precedence: bulk In article <6leve1$2m9g$1 AT newssvr04-int DOT news DOT prodigy DOT com> you wrote: > What do I need to do to set environment variables accessable from batch > files, etc. I have tried both setenv and putenv - neither seems to do > anything, though no error is returned. You don't describe your problem very exactly so part of this is guesswork... I guess you want to change the 'master set' of environment variables, i.e. the one you see after your program has exited and you type 'set', right? If so, that can't be done with setenv, nor with putenv. Both these programs change the environment variables visible *to your program*, and it's children. The trick is that every running program has its own copy of the environment, which it originally inherited from its parent. Any program may change its own environment, or the environment presented to its children (see 'exec*' and 'spawn*' library functions for some details about this), but never the one of its parent, let alone the 'master copy', which is the environment of the parent of all running programs, the originally invoked 'command.com'. (In UNIX environments, hell would break loose if applications were ever allowed to modify, say, their parents' PATH or LD_LIBRARY_PATH variables.) So, in a nutshell: after 'setenv()', the new variable settings will be visible in the program itself (try 'getenv()', to check), and in all programs you invoke from it afterwards, from within the same instance of your program. [Actually, there *are* (undocumented, but reputedly reliable) methods to change the master environment in DOS, but no ordinary user program should have to do that, IMHO.] -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.