如何修复织物中的打印消息问题

How to fix print message issues in fabric

我在 Win10 X64 上使用 Fabric3 1.12.post1。我尝试了以下程序,

from fabric.operations import local
def platform_user():
   print('Platform: ' + local('echo %OS%'))
   print('Username: ' + local('echo %USERNAME%'))

输出是,

[localhost] local: echo %OS%
Windows_NT
Platform:
[localhost] local: echo %USERNAME%
my_user_name
Username:

Done.

'Platform' 和 'Username' 没有与输出对齐,那么如何解决这个问题?

使用 localcapture (http://docs.fabfile.org/en/1.12/api/core/operations.html):

from fabric.operations import local
def platform_user():
    result = local('echo %OS%', capture=True)
    print('Platform: ' + result.stdout)
    result = local('echo %USERNAME%', capture=True)
    print('Username: ' + result.stdout)