Incremental stdout out of fabric

Viewed 232

I'm new to fabric and want to run a long-running script on a remote computer, so far, I have been using something like this:

import fabric
c = fabric.Connection("192.168.8.16") # blocking
result = c.run("long-running-script-outputing-state-information-into-stdout.py")

Is there a way to read stdout as it comes asynchronously instead of using the 'result' object that can be used only after the command has finished?

1 Answers

If you want to use fabric to do some stuff remotely, you have first of all follow this structure to make a connection:

@task(hosts=["servername"])
def do_things(c):
     with connection(host=host, user=user,) as c:
        c.run("long-running-script-outputing-state-information-into-stdout.py")

This will output the whole output regardless what you are doing!

you have to use with connection(host=host, user=user,) as c: to ensure that everything you run will run within that connection context!

Related