私は、リモートマシン上でコマンドを実行しています:ファブリック実行の出力を抑制する簡単な方法は?
remote_output = run('mysqldump --no-data --user=username --password={0} database'.format(password))
私は出力をキャプチャし、それはすべてが画面に印刷されていないしたいと思います。これを行う最も簡単な方法は何ですか?
私は、リモートマシン上でコマンドを実行しています:ファブリック実行の出力を抑制する簡単な方法は?
remote_output = run('mysqldump --no-data --user=username --password={0} database'.format(password))
私は出力をキャプチャし、それはすべてが画面に印刷されていないしたいと思います。これを行う最も簡単な方法は何ですか?
Managing outputセクションはお探しのセクションです。このような何かをしようと、コンソールからの出力を非表示にするには
:
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のは、サンプルの結果である:あなたはログからすべてを隠し、生地を避けたい場合は
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
はこれを試してみてくださいコマンドが失敗したときに例外をスローする:
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)
その後、コマンドresuこの例に示すように、LT:
* 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:これは、プログラムのコンソール出力される
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")
(ファブリックからのメッセージがログに記録されていないことを確認)