Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I capture stderr from Fabric's local command?

Fabric v1.4.3 does not capture the output of 'python --version'

def python_v():
    m = local('python --version', capture=True)
    print(m)
like image 416
Yogesh Mangaj Avatar asked Aug 28 '12 06:08

Yogesh Mangaj


2 Answers

local with capture=True returns the command's stdout; a simple test shows that python --version prints the version info on stderr. So, you can try to redirect stderr to stdout in the command:

m = local('python --version 2>&1', capture=True)
like image 58
Lev Levitsky Avatar answered Oct 31 '22 03:10

Lev Levitsky


I find the following way cleaner than the accepted answer:

print m.stderr

(Thanks remosu!)

like image 24
The Unfun Cat Avatar answered Oct 31 '22 02:10

The Unfun Cat