I want to set environment variables in a shell and then use those variables in subsequent commands; however using subprocess.call() in shell mode does not keep the environment variable set. How do I get the desired functionality through subprocess.
Here is a simplified example of a problem I am having:
import subprocess
#Method 1
subprocess.call('VARNAME1=\"MyValue1\"', shell=True)
subprocess.call("echo $VARNAME1", shell=True)
#Method 2
subprocess.call('VARNAME2=\"MyValue2\"; echo $VARNAME2', shell=True)
Output:
>
> MyValue2
Expected Output:
> MyValue1
> MyValue2
I will not be able to string the commands together with ";" as I did in the second method.
Thanks for the help.