Python Fabric: filter server output when capturing run () output

Consider a Linux server that has the following line in .bash_profileyour user:

echo "Hello world"

So, every time you enter ssh, you see Hello world

Now consider the following fabric script:

#!/usr/bin/env python
from fabric.api import *

env.hosts = [...]

@task
def test():
    with cd('/'):
        print run('ls').split()

You expect it to output something like:   ['tmp', 'etc', 'var', ...]

But the actual output will be:   ['Hello', 'world', 'tmp', 'etc', 'var', ...]

Is this a bug in the ? Is there any way to suppress server output?

time.sleep() Does not help

+4
source share
1 answer

Bash . . , . , script , ( )

[x.x.x.x] Executing task 'test'
[x.x.x.x] run: /bin/bash -l -c "cd / && ls"

-l, bash , env.shell, -l, FAQ.

,

with cd('/'):

with cd('/'), settings(shell='/bin/bash -c'): 
+1

Source: https://habr.com/ru/post/1533018/


All Articles