Python stdin, stdout, stderr

When using Paramiko and the ssh.exec_command function, it contains what are known as three data streams. These are the input, the output, and any errors that may appear. This is known as a 3-tuple. The syntax is:

stdin, stdout, stderr = ssh.exec_command("command")

You can use any variable names you like in place of stdin, stdout, and stderr.

All three of these streams are returned whenever the ssh.exec_command function is executed and they contain the following information:

  • stdin - the input stream. This contains the actual commands that were sent
  • stdout - the output stream. This contains the output that the CLI returns in response to the command
  • stderr - any errors that may have appeared are stored herre.

These streams act as standard Python object files and can be manipulated as such. For example, you can save the output of the previous ssh.exec_command in a variable using the following command:

output = ssh_stdout.readlines().

https://networklessons.com/python/python-ssh

https://forum.networklessons.com/t/python-ssh/10725/25?u=lagapides

https://docs.paramiko.org/en/stable/api/client.html