Calling the source command from subprocess.popen to update the os.environ.

Oscar Benjamin oscar.j.benjamin at gmail.com
Sun Mar 27 10:15:54 EDT 2016


On 27 Mar 2016 17:01, "Ben Finney" <ben+python at benfinney.id.au> wrote:
>
> Hongyi Zhao <hongyi.zhao at gmail.com> writes:
>
> > I use the following code the update the os.environ:
> >
> > import os
> > from subprocess import check_output
> >
> > # POSIX: name shall not contain '=', value doesn't contain '\0'
> > output = check_output("source /home/werner/env-intel-toolchains.sh;
> >          env -0", shell=True, executable="/bin/bash")
>
> That will start a new process (running ‘/bin/bash’), then execute some
> commands from a script file in that process.
>
> When that new process ends, any changes in its environment also
> disappear.

...unless the subprocess prints them out or something.

I think you skimmed the code and question a little too quickly.



More information about the Python-list mailing list