Environment settings always occur in the child process and never directly affect the parent process. However, you can run (in the same child process that changed its environment, at the very end of this process) the command ( env in an environment like Unix, I consider set in DOS, where .bat on Windows, where .cmd files are similar), which outputs the medium to its standard output or to a file; the parent process can read this file and apply the changes in its environment.
On Unix, subprocess.Popen('thescript; env', shell=True, stdout=...) can be enough. On Windows, I'm not sure if the first argument is foo.bat; set foo.bat; set will work; if itβs not, just create a tiny temporary βhelper batβ that does foo.bat , then set , and runs it instead.
source share