Paramiko 的实时输出 exec_command
Real-time output for Paramiko exec_command
注意:我已经看到其他 post 对此,但没有一个 post 可以解释答案,他们也没有有效。
有没有办法实时获取 exec_command
的输出,特别是 exec_command('docker run <CONTAINER_ID>')
的 Paramiko 包?
您可以阅读来自 ChannelFile
(http://docs.paramiko.org/en/2.4/api/channel.html?highlight=stdout#paramiko.channel.ChannelFile) 的行。
示例:
stdin, stdout, stderr = client.exec_command('docker run <CONTAINER_ID>')
while True:
line = stdout.readline()
if not line:
break
print(line, end="")
注意:我已经看到其他 post 对此,但没有一个 post 可以解释答案,他们也没有有效。
有没有办法实时获取 exec_command
的输出,特别是 exec_command('docker run <CONTAINER_ID>')
的 Paramiko 包?
您可以阅读来自 ChannelFile
(http://docs.paramiko.org/en/2.4/api/channel.html?highlight=stdout#paramiko.channel.ChannelFile) 的行。
示例:
stdin, stdout, stderr = client.exec_command('docker run <CONTAINER_ID>')
while True:
line = stdout.readline()
if not line:
break
print(line, end="")