gpt4 book ai didi

python - Paramiko:收集输出的 ssh.exec_command 表示打开 channel 作为响应

转载 作者:太空狗 更新时间:2023-10-30 01:54:41 27 4
gpt4 key购买 nike

我有一些带有 paramiko 和 ssh 的 python 脚本,如下所示

import paramiko

# setup ssh connection this works. no problem.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn = ssh.connect(MACHINEIP, username=ROOTUSER, password=ROOTUSER_PASSWORD, port=22)

# This first ssh exec works perfect.
(sshin1, sshout1, ssherr1) = ssh.exec_command(cmd1)

# When I print the output of 2nd and 3rd ssh exec, I get output saying of channel open
(sshin2, sshout2, ssherr2) = ssh.exec_command(cmd2)
print sshout2
(sshin3, sshout3, ssherr3) = ssh.exec_command(cmd3)
print sshout3

当多次使用 exec_command 收集输出时,输出中的 channel 打开消息:

<paramiko.ChannelFile from <paramiko.Channel 2 (open) window=2097152 
-> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits)
(active; 1 open channel(s))>>>

<paramiko.ChannelFile from <paramiko.Channel 6 (open) window=2097152
-> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits)
(active; 2 open channel(s))>>>

我怎样才能关闭这个开放 channel ? 或者有什么解决办法吗?我正在使用 python 2.7。

最佳答案

应该用作 sshout.read() 而我只在打印时使用 sshout

关于python - Paramiko:收集输出的 ssh.exec_command 表示打开 channel 作为响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20951690/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com