I have a script that adds variables to the environment. That script is called through
subprocess.call('. myscript.sh', shell=True)
Is there a way I can get the modified environment and use it on my next subprocess call?
This questions shows you can get the output of one call and chain it to another call Python subprocess: chaining commands with subprocess.run.
Is there something similar with passing the environment?
Asked
Active
Viewed 49 times
0

Cesar Rios
- 201
- 2
- 5
1 Answers
1
You'll have to output the variables' content somehow. You're spawning a new process which will not propagate the environment variables back, so your python app will not see those values.
You could either make the script echo those to some file, or to the standard output if possible.
(Technically, it would be possible to stop the process and extract the values if you really wanted to hack that, but it's a bad idea.)

viraptor
- 33,322
- 10
- 107
- 191