Redirect Fabric output to a file
Question: I use fabric.api.local directly in my script. For example,

fabric_test.py

    
    
    from fabric.api import local
    
    local('echo hello world')
    local('ls')
    

If I execute it without any io redirection, everything is fine

    
    
    $ python fabric_test.py
    [localhost] local: echo hello world
    hello world
    [localhost] local: ls
    fabric_test.py  test.log
    

If I execute it and redirect the output to a file, the order of the output is
messed up. Why? This problem is really annoying when I use fabric in some
cronjob and send the output to logfiles.

    
    
    $ python fabric_test.py > test.log
    $ cat test.log
    hello world
    fabric_test.py
    test.log
    [localhost] local: echo hello world
    [localhost] local: ls
    


Answer: This is because, fabric essentially executes your designated task as a
separate subprocess. Hence, the subprocess' output isn't the fabric file's
output. This is not a new issue and has been discussed
[before](https://github.com/fabric/fabric/issues/57), please check it out to
see workarounds.

