Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send bash environment variable back to python fabric

I am attempting to pass a bash environment variable back into my fabric function like this:-

from fabric.api import env

def env_localhost():
    "All the environment variables relating to your localhost"
    project_home = local('echo $PROJECT_HOME')
    print 111, project_home

But it doesn't seem to be able to retrieve the stdout results and assign it to my python project_home variable. What's the correct way to do this right?

like image 538
Calvin Cheng Avatar asked Apr 18 '12 05:04

Calvin Cheng


2 Answers

Do it like this:

import os
os.getenv("PATH")
like image 113
WooParadog Avatar answered Nov 12 '22 11:11

WooParadog


Also:

import os
os.environ['PROJECT_HOME']
like image 42
Ali Afshar Avatar answered Nov 12 '22 09:11

Ali Afshar