私はリアルタイムのSSHライブラリを作成しようとしていますが、通常は物事に執着しているので、私はLong-running ssh commands in python paramiko module (and how to end them)からこのコードを取りました。 しかし、このコードは出力全体を出力しません。Paramikoはすべての出力を読む前にプロセスを終了します
whileループがchannel.exit_status_ready()で終了すると、チャネルにはまだ読み込むデータがあると思います。私はこれを修正しようとしてきましたが、修正はすべての入力にあったわけではありません。
どのようにしてこの種のコマンドをすべて印刷することができますか?
import paramiko
import select
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('host.example.com')
channel = client.get_transport().open_session()
channel.exec_command("cd/&& ./test.sh")
while True:
if channel.exit_status_ready():
break
rl, wl, xl = select.select([channel], [], [], 0.0)
if len(rl) > 0:
print channel.recv(1024)
test.sh:
echo 1
wait 1
echo 2
wait 1
echo 3
出力:
1
2
Process finished with exit code 0
感謝。