1

我一直在尝试在 Windows 平台上运行此命令以从 .py 进行 ssh:

child = winpexpect.spawn('ssh %s@%s' % ('myID','m.y.i.p'))

它的功能应该与 pexpect 类似,但我收到此错误:

pexpect.ExceptionPexpect: The command was not found or was not executable: ssh.

我已经确认 C:\rhcygwin\bin 在我的路径中。关于如何指示 .py 文件找到 ssh 命令的任何建议?

编辑:我改变了我的方法:在我的 .py 中运行了这段代码

    command = ['bash', '-c', './myssh.sh']
    proc = subprocess.Popen(command, stdout = subprocess.PIPE)

这是非常基本的,但它会成功连接。

4

2 回答 2

1

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.

于 2012-06-22T20:19:46.207 回答
1

您必须使用 winspawn 方法,并指定 .exe 扩展名:

child = winpexpect.winspawn('ssh.exe %s@%s' % ('myID','m.y.i.p'))
于 2012-10-12T11:51:24.723 回答