我需要这样做:
$ export PYRO_HMAC_KEY=123
$ python -m Pyro4.naming
所以,我发现第二个可以用
subprocess.Popen(['python','-m','Pyro4.naming'])
但是在那之前如何导出 shell 变量呢?
最佳答案
要更新现有环境...
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)
关于python子进程设置shell var。然后运行命令 - 怎么样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11834670/