![Python スクリプトから環境変数を取得する](https://rvso.com/image/170650/Python%20%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%81%8B%E3%82%89%E7%92%B0%E5%A2%83%E5%A4%89%E6%95%B0%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B.png)
config.sh
いくつかの変数がエクスポートされるbash スクリプトがあり、Python スクリプトでそれらの変数が必要です。
config.sh
export VAR="YES"
config.sh
私のアプローチは、Python スクリプトからソースを取得し、os
それを取得することです。
import os
if os.system("source ./config.sh") != 0:
print("Failed to execute the script")
else:
x = os.getenv('VAR')
どういうわけか、x の値はNone
env 変数が見つからないためです。何かアドバイスはありますか? ありがとう
Python バージョン 2.7.5