【问题标题】:Running plink in winpexpect在 winpexpect 中运行 plink
【发布时间】:2011-09-29 02:13:14
【问题描述】:

我正在尝试使用 winpexpect 中的 plink 连接到远程 Linux 服务器。我正在使用以下代码:

child = winpexpect.winspawn('plink root@hostname')
child.logfile = sys.stdout
i = child.expect(['Password:')
child.expect('Password:')
child.sendline('password')

我在标准输出上得到的输出是:

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'>
...

Linux下pexpect中的等效代码(用pexpect替换winpexpect模块,用ssh替换plink调用),所以我知道expect()匹配是正确的。看起来 winpexpect 正在写入屏幕,而 plink 没有将其注册为输入密码字段的文本。

谁能发现这里的问题?

【问题讨论】:

  • 您找到解决方案了吗?我尝试了从 BitBucket 更改的 winpexpect 脚本,但没有成功。谢谢,克里斯
  • 很遗憾,我从未找到解决方案。看起来像是 winpexpect 中的一个错误,但我没有时间自己尝试解决。

标签: python plink


【解决方案1】:

这是一个带有错误修复的分支 winexpect 项目:https://bitbucket.org/weyou/winpexpect 你可以试试。

【讨论】:

    【解决方案2】:

    我遇到了与 winpexpect 和 plink 类似的问题。 This question 有一个对我有用的解决方案。连接到我的串行接口的设备在本地回显内容并使 winpexpect 感到困惑。将 sendline() 替换为执行以下操作的函数:

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

    每次通话都为我修复。 child.pexpect(cmd) 在目标种子 \n 之前吃掉本地回显的字符并开始响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 2015-07-16
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多