4

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
  • 512
  • 2
  • 13
  • 27

1 Answers1

9

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
  • 5,414
  • 6
  • 40
  • 72
gbajson
  • 1,531
  • 13
  • 32