- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经被这个问题困扰好几天了,但我不知道出了什么问题。
我有一个简单的 python 脚本,使用 pexpect 在 OSX 上运行,它启动 ssh-keygen 并自动按回车键生成 key 对,并且工作正常。我想在 Windows 上做同样的事情。为了在 Windows 上获取 ssh 和 ssh-keygen,我安装了 OpenSSH for Windows,它允许 ssh 使用部分 CYGWIN 支持文件作为普通 Windows 程序从 cmd 提示符运行。我将相同的脚本移植到 Windows 并将 pexpect 更改为 winpexpect 并使用相应的 winspawn 来启动子进程,但它在第一个提示符处就停止了。
def generateKeys(self):
print "GeneratingKeys..."
gen = winpexpect.winspawn("ssh-keygen -t rsa")
print gen.expect(":") #This is where it asks for a place to save the keys. retuns 0 if found
print "before: " + gen.before
print "after: " + gen.after
print gen.sendline()
#Next it should expect a prompt for a passphrase but it never reaches it
print gen.expect(":")
print "before: " + gen.before
print "after: " + gen.after
print gen.sendline()
我得到的输出是这样的:
GeneratingKeys...
0
before: Enter file in which to save the key (/home/user/.ssh/id_rsa)
after: :
2
before: Enter file in which to save the key (/home/user/.ssh/id_rsa)
after: :
它就在这里,供所有永恒收集数字灰尘的兔子使用。
我也不明白为什么它在预期的冒号后面会出现“:”。
我是否可以使用另一个模块来更好地与 Windows 版 OpenSSH 进行通信?
最佳答案
不久前,我查看了winpexpect。我也无法让它运行,它只是挂着。如果我没记错的话,与不受支持的部分和不完整的端口有关。
由于我需要它用于 ssh,所以我最终将其替换为 paramiko 。它需要 pycrypto,这在 Windows 上设置起来很痛苦,除非你使用 precompiled installer 。对于 key 生成,请参阅this section of the docs 。它具有 key 的加载和保存。还要注意缺少主机 key 功能。
为了快速启动并运行,这里有一个 overview 。请注意,它并没有涵盖所有函数调用,例如为什么他使用 AutoAddPolicy()
。检查文档以了解优点/缺点以及更多详细信息。
关于python - winpexpect 的行为不像 pexpect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10789455/
我一直在尝试在 Windows 平台上从 .py 运行此命令以进行 ssh: child = winpexpect.spawn('ssh %s@%s' % ('myID','m.y.i.p')) 它的
我已经被这个问题困扰好几天了,但我不知道出了什么问题。 我有一个简单的 python 脚本,使用 pexpect 在 OSX 上运行,它启动 ssh-keygen 并自动按回车键生成 key 对,并且
我尝试在带有 python 2.6 的 Windows 7 64 位上使用 winpexpect。 >>> import winpexpect Traceback (most recent call
我是一名优秀的程序员,十分优秀!