[Python-au] Environment vars
mhammond at skippinet.com.au
Thu Aug 18 09:03:26 CEST 2005
> Grant McDonald wrote:
> > Not entirely sure,
> > The docs say you should modify os.environ directly since it
> > calls putenv, but as you stated on WinXP and as you say it
> doesn't seem to
> > work. I guess putenv may not be supported on WinXP.
> > If you want a reliable way of modifying the environment on WinXP use the
> > registry (unfortunately platform specific):
> I'd prefer to stay platform neutral. I think I'll detect os.name and
> scribble out a batch file to set a couple of vars if it is 'nt'.
This is how environment variables work on all platforms. Each process gets
an environment, specified by its parent. os.putenv etc all set the
*current* process' environment variable - you can not set environment
variables in your parent process.
Thus, in a .bat file, cmd.exe is the parent of your python.exe. This
python.exe can not change the cmd.exe environment. You will have to arrange
some way of having the parent process read the env vars (such as writing a
temp .bat file or shell script the parent then calls after your process is
complete). I don't believe there is a platform neutral syntax you can use
for this temp script though.
Even on Windows, hacking the registry will not have the affect you desire -
as the parent process will already be running, changing the registry will
not affect that process.
More information about the python-au