Fabric 脚本在成功时不打印输出

Fabric script doesn't printing output on success

import sys
from fabric.api import *

env.hosts = ['my.host.com']
env.user = 'myuser'
env.password = 'mypassword'
# env.shell = '/bin/bash -l -c'

def deploy():
    x = run("cd /srv/proj/")
    print x.__dict__

我正在尝试登录远程 shell 并执行这个简单的 cd 命令。 虽然显示没有错误

[my.host.com] run: cd /srv/proj/
{'succeeded': True, 'return_code': 0, 'failed': False, 'command': 'cd /srv/proj/', 'stderr': '', 'real_command': '/bin/bash -l -c "cd /srv/proj/"'}

但是当我在 cd 命令后执行 run('ls') 时,它什么也不打印,但肯定有文件。所以这里发生了什么。除此之外,我在执行手动设置命令时遇到问题(我的意思是 .bashrc 文件中的别名)。面料使用 /bin/bash -l -c ...。我怎样才能克服这个障碍。

我正在使用 ubuntu 14.04

ps:与os.chdir

不同

你可以试试 with cd :

def deploy():
    with cd("/srv/proj/"):
        x = run("ls")
    print(x)