开发者

Paramiko X11 mode with python programming

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.

Here is the code I tried:


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

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  

Unfortunately, my application freezes at the moment that the X11 window should normally appear. Remark : If I l开发者_运维技巧aunch a command without a X11 window displaying, it works perfectly.

Thank you for your help,

Regards


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.

Here, assign a function for incoming X11 connections.

chan.request_x11 (handler=testFunc())  

And write a simple one.

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.


Reading the paramiko code, I realized that paramiko only implements a way to establish an x11 channel. It does not connect the channel to the local x11 display. That is left to you.

Please see this answer for a working example of how to do this: https://stackoverflow.com/a/12903844/72911

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜