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