2012-02-26 16 views

Odpowiedz

31

To brzmi jak sekcja Managing output, której szukasz.

Aby ukryć wyjście z konsoli, spróbuj coś takiego:

from __future__ import with_statement 
from fabric.api import hide, run, get 

with hide('output'): 
    run('mysqldump --no-data test | tee test.create_table') 
    get('~/test.create_table', '~/test.create_table') 

belows Czy wyniki próbki:

No hosts found. Please specify (single) host string for connection: 192.168.6.142 
[192.168.6.142] run: mysqldump --no-data test | tee test.create_table 
[192.168.6.142] download: /home/quanta/test.create_table <- /home/quanta/test.create_table 
17

spróbować tego, czy chcesz, aby ukryć wszystko z dziennika i uniknąć tkaniny rzucanie wyjątków, gdy polecenie nie powiedzie się:

from __future__ import with_statement 
from fabric.api import env,run,hide,settings 

env.host_string = '[email protected]' 
env.key_filename = '/path/to/key.pem' 

def exec_remote_cmd(cmd): 
    with hide('output','running','warnings'), settings(warn_only=True): 
     return run(cmd) 

Po tym można sprawdzić komendy resu lt, jak pokazano w poniższym przykładzie:

cmd_list = ['ls', 'lss'] 
for cmd in cmd_list: 
    result = exec_remote_cmd(cmd) 
    if result.succeeded: 
     sys.stdout.write('\n* Command succeeded: '+cmd+'\n') 
     sys.stdout.write(result+"\n") 
    else: 
     sys.stdout.write('\n* Command failed: '+cmd+'\n') 
     sys.stdout.write(result+"\n") 

to będzie wyjście konsoli programu (zwrócić uwagę, że nie są wiadomości z tkaniny log):

 
* Command succeeded: ls 
Desktop espaiorgcats.sql Pictures Public  Videos 
Documents examples.desktop projectes scripts 
Downloads Music   prueba Templates 

* Command failed: lss 
/bin/bash: lss: command not found 
Powiązane problemy