title: open a putty window and run ssh commands - Python
body: <p>I am new to python. I need to login to a server daily (Desktop -> 1.32 -> 0.20 -> 3.26). For this I need to open putty and using ssh connection i am logging in. To do all this I want to write a script using python.  </p>
  
  <p>By using google I thought subprocess.Popen will do that. But Its not working fine.</p>
  
  <p>1st trail:</p>
  
  <pre><code>import subprocess
  pid = subprocess.Popen("putty.exe user@xxx.xx.x.32 -pw password").pid
  </code></pre>
  
  <p>Its working fine (Opening window logging into .32). But cant able to give input. I came to know that to give input for the same process we need to use pipes.</p>
  
  <p>2nd trail:</p>
  
  <pre><code>from subprocess import Popen, PIPE, STDOUT
  p = Popen("putty.exe user@xxx.xx.x.32 -pw password", stdout=PIPE, stdin=PIPE, stderr=STDOUT)    
  grep_stdout = p.communicate(input=b'ssh xx.xx.x.20\n')[0]
  print(grep_stdout.decode())
  </code></pre>
  
  <p>by using this i cant login for the first server also. After logging in to all servers I need the terminal as alive. how to do this???</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I need to do this in a new putty window. After logging in dont close the window. I have some manual work to do.</p>