【发布时间】:2015-08-12 19:09:19
【问题描述】:
我有一个调用 bash 脚本的 python2.7 脚本,在 bash 脚本中我正在导出 2 个变量,我尝试使用 declare -x 和 export,然后我正在尝试读取这些变量在python脚本中使用os.getenv,我也尝试使用os.environ,但我每次都得到Nonetype。
这是我脚本中的一个 sn-p:
Python:
def set_perforce_workspace():
global workspace_path
global workspace_root_path
script_path = "somePath"
depot_name = "TestingTools"
dir_to_download = "vtf"
bash_command = "./createWorkspace.sh " + "-d " + depot_name + " -w " \
+ PerforceUtils.WORKSPACE_NAME + " -a " + dir_to_download
print bash_command
print os.getcwd()
try:
os.chdir(script_path)
except OSError as e:
print "Error: {0}".format(e)
print os.getcwd()
return_code = call([bash_command], shell=True)
test = os.getenv("workspace_path")
print "this is test {0}".format(test)
workspace_path = os.getenv("workspace_path")
workspace_root_path = os.getenv("workspace_root_path")
print "This is the return code {0}".format(return_code)
print "this is the workspace path: {0}".format(workspace_path)
print "this is the workspace root path: {0}".format(workspace_root_path)
return return_code
重击:
declare -x workspace_root_path="$workspaceProjPath"
export workspace_path="$workspaceProjPathLocal"
【问题讨论】:
标签: python bash python-2.7 subprocess