I need to do this:
$ export PYRO_HMAC_KEY=123 $ python -m Pyro4.naming
So, I found that the second can be done with
subprocess.Popen(['python','-m','Pyro4.naming'])
but how to export a shell variable before that?
To upgrade an 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)
The subprocess functions take an argument env , which can be assigned a mapping of environment variables for use in the process:
env
subprocess.Popen(['python','-m','Pyro4.naming'], env={'PYRO_HMAC_KEY': '123'})
Try os.putenv (): http://docs.python.org/library/os.html#os.putenv