I am trying to source a shell script from python.
I have tried to do that in several ways.
One of which:
def source(script, update=1):
pipe = Popen(f". {script}; env", stdout=PIPE, shell=True)
data = pipe.communicate()[0]
env = dict(str(line).split("=", 1) for line in data.splitlines())
if update:
environ.update(env)
return env
I have also tried exec(file) and os.system. None of which seems to give me the ability to keep the environment variables on the shell from which I run the python script. Does anyone of you have any idea how I can do that?