亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 get_pty=False 將 Ctrl+C 發送到 Python Paramiko

如何使用 get_pty=False 將 Ctrl+C 發送到 Python Paramiko

哈士奇WWW 2023-03-08 15:51:07
我想使用帶有 get_pty=False 選項的 paramiko 客戶端。我們有辦法發送中斷信號嗎?我有一些想法喜歡使用 client.close() 但我更想知道為什么發送"\0x03"失敗get_pty=False。import paramikoclient = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.AutoAddPolicy())connection_param= {'hostname': '192.168.255.1',            'username': 'username',            'password': 'password',            'port': '22',            'timeout': 15,            'key_filename': None,            'pkey': None}client.connect(**connection_param)stdin, stdout, stderr = client.exec_command("tail -f /tmp/test.log", bufsize=-1, timeout=None, get_pty=True)time.sleep(1)print(stdin.channel.exit_status_ready())  # Falsestdin.write("\x03".encode())stdin.channel.close()print(stdout.read().decode(errors='ignore')) # File outputprint(stdin.channel.exit_status_ready())  # Truestdin, stdout, stderr = client.exec_command("tail -f /tmp/test.log", bufsize=-1, timeout=None, get_pty=False)time.sleep(1)print(stdin.channel.exit_status_ready())  # Falsestdin.channel.close()   # hangs in next step for stdin.write("\x03".encode())print(stdout.read().decode(errors='ignore')) # File outputprint(stdin.channel.exit_status_ready())  # True我們還有其他方法可以使用stdin.write()for發送中斷信號嗎get_pty=False?
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

我相信這Ctrl+C是一個終止信號。如果沒有終結符 ( get_pty=false),則沒有任何特殊含義。

如果要終止遠程命令,只需關閉“exec”通道即可。

stdin.channel.close()

你已經在做什么了。


查看完整回答
反對 回復 2023-03-08
  • 1 回答
  • 0 關注
  • 253 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號