简体   繁体   中英

Setting environment environment variables with a Python script

OS: Mac OSX 10.14 Python 2.7

I have a python script which looks like below:

#! /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')

The env_variables_file looks like this:

passwordA='abcd';
passwordB='1234';
export passwordA passwordB

The anotherpythonscript.py will only work properly if the environment variables above are set properly. When i run it via the main python script it does not define the variables. Although, if i run the ./env_variables_file directly from the command line it will set the environment variables. Any suggestions how to run this through the Python script and have it set the environment variables.

See comment above:

#!/usr/bin/env bash
./binaryfileproducesenv_variables > ./env_variables_file
. ./env_variables_file
python anotherpythonscript.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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