Python: Persistent shell variables in subprocess

[亡魂溺海] 提交于 2019-11-30 20:11:00

subprocess.Popen takes an optional named argument env that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of os.environ and alter that as you need) and pass it to all the subprocess.Popen calls you perform.

Alex is absolutely correct. To give an example

current_env=environ.copy()
current_env["XXX"] = "SOMETHING" #If you want to change some env variable
subProcess.Popen("command_n_args", env=current_env)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!