Modifying environment variables

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Dec 21 17:37:45 EST 2001


Terry Hancock <hancock at anansispaceworks.com> writes:

> However, all this work is wasted, because after
> I leave the script, the PATH is unaffected. It
> seems that assigning values to os.environ['PATH']
> can affect subshells, but not the one I'm running
> the script from.

Yes, this is the way Unix works. You can inherit environment variables
from the parent process to the child process, but once a process is
started (such as the shell), you cannot affect their environment
variables from the outside. Everything else would open big security
holes.

> Is there a way to get around this limitation?

Print a shell command on standard output, then, in the shell,
do 

eval `script_name`

HTH,
Martin



More information about the Python-list mailing list