SSH和发送命令在Tkinter?

时间:2013-02-26 18:34:55

标签: python ssh tkinter tcl expect

我正在尝试使用Tkinter将代码从TCL转换为python。 我想知道Tkinter中的等效代码是什么 “spawn ssh”,“expect”和“send”? 例如,我的简单tcl程序就像:

spawn ssh root@138.120.###.###
expect "(yes/no)?" {send -- "yes\r"}
expect "password" {send -- "thepassword\r"}

2 个答案:

答案 0 :(得分:2)

您可以尝试使用pexpect

Expect用于自动化其他命令行工具。

编辑:诅咒你可以尝试通过Tkinter执行package require Expect,但是对纯Tcl脚本有什么好处呢?毕竟你编写了Tcl代码,然后用python包装。

另一个编辑:Tkinter用于从python访问Tk(很酷的GUI工具包:P),它可以通过调用某个地方的Tcl命令来工作。因此,您可以将每个tcl程序转换为python(如果您当然安装了正确的tcl库)。

答案 1 :(得分:0)

pxpect有一个名为pxssh的模块,它可以完成很多操作简单ssh会话的工作。我发现这不足以进行繁重的自动化,并将remote写为附件以增加错误处理。

使用pxssh

from pxssh import pxssh
p = pxssh()
p.login('host', 'user', 'password')
p.send('command')

使用远程

from remote import remote
r = remote('host', 'user', 'password')
if r.login():
  r.send('command')

我不确定Tkinter的用例,我唯一的假设是你用它来制作一个gui,并且有许多教程。我之前使用过http://sebsauvage.net/python/gui/,它比较了Tkinter和wxPython。