Environment settings always happen in the child process and never directly affect the parent process. However you can run (in the same child process that has changed its environment, at the very end of that process) a command (env
in Unix-like environment, I believe set
in DOS where .bat
files lived and in Windows where .cmd
files are similar) that outputs the environment to its standard-output, or to a file; the parent process can read that file and apply the changes to its own environment.
In Unix, subprocess.Popen('thescript; env', shell=True, stdout=...)
may suffice. In Windows, I'm not sure passing as the first argument foo.bat; set
would work; if it doesn't, just create a tiny temporary "auxiliary bat" that does foo.bat
then set
, and run that one instead.