Calvin Cheng
Calvin Cheng

Reputation: 36556

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?

Upvotes: 5

Views: 1012

Answers (2)

Ali Afshar
Ali Afshar

Reputation: 41657

Also:

import os
os.environ['PROJECT_HOME']

Upvotes: 3

WooParadog
WooParadog

Reputation: 649

Do it like this:

import os
os.getenv("PATH")

Upvotes: 6

Related Questions