[Python-au] Environment vars

Grant McDonald gmcdonald at infocomp.com
Thu Aug 18 09:09:03 CEST 2005


Thats the difference between setting _system_ properties and setting
_session_ properties. If it's a matter of persistent environment changes
then the registry is useful from a configuration point of view.

-----Original Message-----
From: Mark Hammond [mailto:mhammond at skippinet.com.au]
Sent: 18 August 2005 17:03
To: Mike Dewhirst; Grant McDonald
Cc: python-au at python.net
Subject: RE: [Python-au] Environment vars


> Grant McDonald wrote:
> > Not entirely sure,
> >
> > The docs say you should modify os.environ directly since it
> automatically
> > 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.

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/python-au/attachments/20050818/98e95227/attachment.htm


More information about the python-au mailing list