I'm trying to use plink in winpexpect to connect to a remote Linux server. I'm using the following code:
child = winpexpect.winspawn('plink root@hostname')
child.logfile = sys.stdout
i = child.expect(['Password:')
child.expect('Password:')
child.sendline('password')
The output I get on stdout is:
Using keyboard-interactive authentication.
Password: password
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
...
command: plink
args: ['plink', 'root@hostname']
buffer (last 100 chars): yboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password:
before (last 100 chars): yboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Password:
after: <class 'pexpect.TIMEOUT'>
...
The equivalent code works in pexpect under Linux (replacing the winpexpect module with pexpect, and the plink call with ssh), so I know that the expect() matching is correct. It looks like winpexpect is writing to the screen, and plink is not registering that as being text entered into the password field.
Can anyone spot the problem here?