I try execute csh script(which creates or updates environment variables) from python but environment variables don't update after return to shell. Why ? How can I solve it ?
subprocess.call('script.csh',shell=True,executable="/bin/csh")
I try execute csh script(which creates or updates environment variables) from python but environment variables don't update after return to shell. Why ? How can I solve it ?
subprocess.call('script.csh',shell=True,executable="/bin/csh")
To set an environment variable in python, use
os.environ['YOUR_VARIABLE'] = "your_value"
Note that environment variables must be strings.
Explanation for why you cannot do what you want to do:
Environment variables are set in a per process memory space. When bash (or whatever shell have you) runs a program, it uses fork(), which inherits bash’s variables because it is a child process. What your trying to do is create a child process and have he parent inherit from the child, like @PM 2Ring said.