[英]Setting environment environment variables with a Python script
操作系統:Mac OSX 10.14 Python 2.7
我有一個 python 腳本,如下所示:
#! /usr/bin/python
import os
os.system('./binaryfileproducesenv_variables > ./env_variables_file')
os.system('chmod 744 ./env_variables_file')
os.system('./env_variables_file')
os.system('python anotherpythonscript.py')
env_variables_file 看起來像這樣:
passwordA='abcd';
passwordB='1234';
export passwordA passwordB
如果上面的環境變量設置正確,anotherpythonscript.py 才會正常工作。 當我通過主 python 腳本運行它時,它沒有定義變量。 雖然,如果我直接從命令行運行 ./env_variables_file ,它將設置環境變量。 關於如何通過 Python 腳本運行它並讓它設置環境變量的任何建議。
看上面的評論:
#!/usr/bin/env bash
./binaryfileproducesenv_variables > ./env_variables_file
. ./env_variables_file
python anotherpythonscript.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.