Reputation: 3491
I need to do this:
$ export PYRO_HMAC_KEY=123
$ python -m Pyro4.naming
So, i found that the second one is possible to do with
subprocess.Popen(['python','-m','Pyro4.naming'])
but how export shell variable before that?
Upvotes: 10
Views: 18612
Reputation: 532093
To update the existing environment...
import os, subprocess
d = dict(os.environ) # Make a copy of the current environment
d['PYRO_HMAC_KEY'] = '123'
subprocess.Popen(['python', '-m', 'Pyro4.naming'], env=d)
Upvotes: 29
Reputation: 3235
Try os.putenv(): http://docs.python.org/library/os.html#os.putenv
Upvotes: 0
Reputation: 208635
The subprocess functions accept an env
argument that can be given a mapping of environment variables to use in the process:
subprocess.Popen(['python','-m','Pyro4.naming'], env={'PYRO_HMAC_KEY': '123'})
Upvotes: 9