1

我没有设法通过其 ssh X11 管理功能使用 Paramiko python 模块。
我想像使用 ssh -X 选项一样使用它。
我尝试了几种解决方案,但在我的系统上没有任何效果。

这是我尝试过的代码:


client = paramiko.SSHClient()   
client.set_missing_host_key_policy(AutoAddPolicy())   
client.connect(machineName, username=xxx, password=xxx)  
t = client.get_transport ()  
chan = t.open_session ()  
chan.request_x11 ()  
chan.set_combine_stderr (True)  
chan.exec_command (xxxxx)  # the command that should display a X11 window  
bufsize = -1  
stdin = chan.makefile('wb', bufsize)  
stdout = chan.makefile('rb', bufsize)  
stderr = chan.makefile_stderr('rb', bufsize)  
for line in stdout:   
    print '... ' + line.strip('\n')  
client.close()  

我也试过(而不是 exec_command):

chan.get_pty("vt100", 80, 50)  
chan.invoke_shell()  
chan.send(xxxxx) # the command that should display a X11 window  

不幸的是,我的应用程序在 X11 窗口正常出现时冻结了。备注:如果我在没有显示 X11 窗口的情况下启动命令,它会完美运行。

谢谢你的帮助,
问候

4

2 回答 2

1

我需要使用 paramiko 在另一个 X11 窗口中运行 GUI 并找到了这篇文章。我认为您可能需要添加几行才能使其正常工作。这都是关于处理程序参数的。

在这里,为传入的 X11 连接分配一个功能。

chan.request_x11 (handler=testFunc())  

并写一个简单的。

import commands
def testFunc():
    cmd = "xterm"
    result = commands.getoutput(cmd)

之后它应该会弹出一个新窗口。至少它对我有用。

于 2011-10-06T18:45:36.970 回答
1

阅读 paramiko 代码,我意识到 paramiko 只是实现了一种建立 x11 通道的方法。它不会将通道连接到本地 x11 显示器。那是留给你的。

请参阅此答案以获取有关如何执行此操作的工作示例:https ://stackoverflow.com/a/12903844/72911

于 2012-10-15T21:11:07.183 回答