0

I basically want to set path for some of the variables using source . Scripting language python .subprocess.call call source /home/local/APPSCRIPT.env but not actually setting the environment variable.

sample script :

import os
from subprocess import Popen, PIPE
import subprocess

subcall=subprocess.call(['source /home/local/APPSCRIPT.env'],shell=True)

Please suggest how can i set the environment variable from APPSCRIPT.env

APPSCRIPT.env :

export xxx_SIZE=1
export yyy_USE=FALSE
export zzz_INCREMENTAL=FALSE

1 Answer 1

2

You can't do this.

subprocess runs in, well, a subprocess. There's no way for any environment changes made in a subprocess to affect the calling process.

The only way to change environment variables for the current process in Python is to directly modify the sys.environ dictionary.

Sign up to request clarification or add additional context in comments.

3 Comments

Are the changes made in the sys.environ dict accessible from outside Python? say from the cmd for example?
No, for precisely the same reason.
I have to set multiple environment variable in one shot . Could you please give some example or any doc link so i can refer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.