3

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?

M. Barbieri
  • 452
  • 2
  • 11
  • 23

1 Answers1

7

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="")
SomeGuyOnAComputer
  • 4,177
  • 5
  • 33
  • 58
gbajson
  • 1,367
  • 10
  • 26