带python编程的Paramiko X11模式 [英] Paramiko X11 mode with python programming

查看:81
本文介绍了带python编程的Paramiko X11模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I do not manage to use the Paramiko python module passing through its ssh X11 management functionality.
I would like to use it as if I used the ssh -X option.
I have tried several solution but nothing work on my system.

这是我试过的代码:

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):


I also tried (instead of the exec_command) :

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

<小时>

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


Unfortunately, my application freezes at the moment that the X11 window should normally appear. Remark : If I launch a command without a X11 window displaying, it works perfectly.

感谢您的帮助,
问候

Thank you for your help,
Regards

推荐答案

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

I needed to use paramiko to run the GUI in another X11 window and found this post. I think you may need to add few lines to make it work. It's all about the handler parameter.

在这里,为传入的 X11 连接分配一个函数.

Here, assign a function for incoming X11 connections.

chan.request_x11 (handler=testFunc())  

然后写一个简单的.

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

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

It should pop out a new window after that. At least it works for me.

这篇关于带python编程的Paramiko X11模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆