标题已经说明了一切。
假设我有一个bash脚本:
```bash ```
我该如何从Python运行此脚本并检查设置了哪些环境变量。理想情况下,我希望将它们“反向继承”到正在运行Python的主环境中。
这样我就可以通过以下方式访问它们:
假设我有一个bash脚本:
```bash ```
#!/bin/bash
# do some magic here, perhaps fetch something with wget, and then:
if [ "$VAR1" = "foo" ]; then
export CASEVARA=1
fi
export CASEVARB=2
# and potentially many other vars...
我该如何从Python运行此脚本并检查设置了哪些环境变量。理想情况下,我希望将它们“反向继承”到正在运行Python的主环境中。
这样我就可以通过以下方式访问它们:
import os
# run the bash script somehow
print os.environ['CASEVARA']