I am trying to write a python script that will be SSH on the server and execute a command. I use Python 2.6 for Windows and installed plink and paegent (for ssh keys) and added them all to my path.
If I go to the command line and type:
plink username@host -i key.ppk open vnc:
I see the desired behavior - the VNC viewer opens on my Mac (server).
However, if I tried two approaches to do this programmatically through Python, and none of them work:
Approach 1 (os):
import os ff=os.popen("plink user@host -i key.ppk",'w') print >>ff, r"open vnc://www.example.com" ff.flush()
Approach 2 (subprocess):
import subprocess ff=subprocess.Popen("plink user@host -i key.ppk",shell=False,stdin=subprocess.PIPE) ff.stdin.write(r"open vnc://www.example.com") ff.stdin.flush()
None of the approaches generate an error, but open a VNC window. However, I believe that they both successfully connect to the remote host.
What am I doing wrong?
python subprocess putty ssh plink
Jeff
source share