想在python脚本里面source .profile,调用os.system后在当前运行的脚本里环境变量没有变呢?求解决方法。
3个回答
展开全部
在Python中环境变量的正确获取方法应该是os.environ返回的是个dict类型的数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
source is not an executable command, it's a shell builtin.
The most usual case for using source is to run a shell script that changes the environment and to retain that environment in the current shell. That's exactly how virtualenv works to modify the default python environment.
Creating a sub-process and using source in the subprocess probably won't do anything useful, it won't modify the environment of the parent process, none of the side-effects of using the sourced script will take place.
Python has an analogous command, execfile, which runs the specified file using the current python global namespace (or another, if you supply one), that you could use in a similar way as the bash command source.
https://stackoverflow.com/questions/7040592/calling-the-source-command-from-subprocess-popen
The most usual case for using source is to run a shell script that changes the environment and to retain that environment in the current shell. That's exactly how virtualenv works to modify the default python environment.
Creating a sub-process and using source in the subprocess probably won't do anything useful, it won't modify the environment of the parent process, none of the side-effects of using the sourced script will take place.
Python has an analogous command, execfile, which runs the specified file using the current python global namespace (or another, if you supply one), that you could use in a similar way as the bash command source.
https://stackoverflow.com/questions/7040592/calling-the-source-command-from-subprocess-popen
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询