Reputation: 157
I've been trying to run this command to ssh from a .py on a Windows platform:
child = winpexpect.spawn('ssh %s@%s' % ('myID','m.y.i.p'))
It should function similarly to pexpect, but I receive this error:
pexpect.ExceptionPexpect: The command was not found or was not executable: ssh.
I've confirmed that C:\rhcygwin\bin is in my Path. Any suggestions on how to instruct the .py file to locate the ssh command?
edit: I switched my approach: ran this code in my .py
command = ['bash', '-c', './myssh.sh']
proc = subprocess.Popen(command, stdout = subprocess.PIPE)
it's very rudimentary but it will connect successfully.
Upvotes: 1
Views: 4047
Reputation: 97
You have to use the winspawn method, and specify the .exe extension:
child = winpexpect.winspawn('ssh.exe %s@%s' % ('myID','m.y.i.p'))
Upvotes: 1
Reputation: 14910
As far as I'm aware, pexect does not actually work on windows. There was a partial port attempt, but it was broken the last time I checked it.
If you want to automate doing something over ssh with python on windows, you will probably have better luck with the paramiko library. There are good docs, but you will need to compile pycrypto, or else get a precompiled binary.
Upvotes: 1