I use the Paramiko Python package to run commands over SSH. I can get output to stdout but how can I properly get stdout, stderr and stdin redirected to the sys ones?
The code below would only display "stdout1" and "stdout2" on stdout. How do I get "stderr" in there properly? And preferably also support for stdin?
import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect("localhost")
stdin, stdout, stderr = ssh.exec_command("echo stdout1 >&1; echo stderr >&2; echo stdout2 >&1")
ch = stdout.channel
while True:
bs = ch.recv(1)
if not bs:
break
print(bs.decode("utf-8"), end="")