Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real-time output for Paramiko exec_command [duplicate]

NOTE: I have seen other posts on this, but not a single post can explain the answer, nor do they have one that works.

Is there a way to get the output of exec_command, specifically for exec_command('docker run <CONTAINER_ID>') in real-time for the Paramiko package?

like image 803
M. Barbieri Avatar asked Nov 06 '25 04:11

M. Barbieri


1 Answers

You may read lines from ChannelFile (http://docs.paramiko.org/en/2.4/api/channel.html?highlight=stdout#paramiko.channel.ChannelFile).

Example:

stdin, stdout, stderr = client.exec_command('docker run <CONTAINER_ID>')
while True:
    line = stdout.readline()
    if not line:
        break
    print(line, end="")
like image 198
gbajson Avatar answered Nov 08 '25 01:11

gbajson