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 a string) or stdout.readlines() (returns a list of lines).


stdin, stdout, stderr = ssh.exec_command("ls")
output =

Also see our full example: Paramiko SSH client minimal example: How to connect to SSH server and execute command