Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect Fabric output to a file

Tags:

python

fabric

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
like image 350
Ryan Ye Avatar asked Nov 27 '25 04:11

Ryan Ye


1 Answers

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, please check it out to see workarounds.

like image 53
Games Brainiac Avatar answered Nov 28 '25 19:11

Games Brainiac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!