繁体   English   中英

使用 Python 脚本设置环境环境变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM