I want to open a PuTTY window, login to some server and enter few commands right after that and at the end save the output. I want to see the PuTTY window open and all activity that I am doing via program (hence need PuTTY GUI).
Here is what I have tried:
I am able to open a new window and login in it. But using stdin.write
I am not able to enter further commands in the same window. What am I doing wrong here? I am very new to python. Please help.
import subprocess
from subprocess import Popen, PIPE, STDOUT
p = subprocess.Popen("putty.exe demo@Test.Rebex.Net -pw password", stdout=PIPE, stdin=PIPE, stderr=STDOUT)
p.stdin.write("ls".encode("utf-8"))
print(p.stdout.readlines())
I have tried Paramiko, and don't want to use it, as it fails to display/print the output of commands like top
.