Paramiko: How to execute command and get output as string
Using exec_command() in Paramiko returns a tuple (stdin, stdout, stderr). Most of the time, you just want to read stdout and ignore stdin and stderr. You can get the output the command by using stdout.read()(returns a string) or stdout.readlines() (returns a list of lines).
Example:
exec_command_example.py
stdin, stdout, stderr = ssh.exec_command("ls")
output = stdout.read()
print(output)Also see our full example: Paramiko SSH client minimal example: How to connect to SSH server and execute command
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow