2016-12-07 53 views
0

我在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. 

「平臺」和「用戶名」並沒有隨着產出排隊,那麼如何解決這個問題?

回答

1

使用localcapturehttp://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)