1

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 launch a command without a X11 window displaying, it works perfectly.

Thank you for your help,
Regards

1
  • Is your DISPLAY environment variable set on the remote shell? If so what is it set to? Commented Dec 15, 2010 at 10:48

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes it works under Linux. Congratulation. Thanks for your answer.
With the code above, testFunc is executed locally (note that it's called before request_x11 and that its return value is used as the handler parameter), so it doesn't seem to be correct.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.