Symmetric
Symmetric

Reputation: 4723

Running plink in winpexpect

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?

Upvotes: 2

Views: 2198

Answers (2)

Alex
Alex

Reputation: 471

I ran in to a similar issue with winpexpect and plink. This question had a solution that worked for me. The device attached to my serial interface was echoing things locally and confusing winpexpect. Replacing the sendline() with a function that does:

    child.send(cmd)
    child.pexpect(cmd)
    child.send('\n')

for each call fixed it for me. the child.pexpect(cmd) eats the locally echoed characters before the target seed the \n and starts responding.

Upvotes: 0

Jruv
Jruv

Reputation: 1598

Here is a forked winexpect project with bug fix: https://bitbucket.org/weyou/winpexpect You can try it.

Upvotes: 2

Related Questions