问题
I am using Python and wxpython for gui. I am trying to connect ssh tunnel. After connecting to ssh, wants a new terminal to open and have to continue my operation in local machine. How to achieve this?
I tried subprocess, pexpect and paramiko, but all are capable to connect to ssh but not open the new teminal
Below my code is there which I tried with pexpect:
import time
import sys
import pexpect
c = pexpect.spawn("ssh -Y -L xxxx:localhost:xxxx user @ host.com")
time.sleep(0.1)
c.expect("[pP]aasword")
c.sendline("xxxxxx")
time.sleep(0.2)
c.interact()
c.pexpect([user@host.com~]$)
# here after its connects to ssh then command wont be executed
c.sendline("xfce4-terminal")
On 24/04/2013 I am able to open new terminal but what happens is when the new terminal will open controls from gui doesn't go there. Any help?
回答1:
Opening a new local terminal and connecting an existing process in to it is a little complicated. There are at least three approaches:
Open the terminal before you start connecting, and run all the code that tries to establish the connection from within it. This is simplest. The main drawback is that the terminal will appear even if the connection fails, which might be what you want to avoid.
Run the connection attempt with a session of
tmux
orscreen
and if you detect that it succeeded then reattach that session in to a new terminal.Make your Python program provide a pty that the terminal can attach to - your program will need to hang around and pass input and output between the remote connection and the pty.
来源:https://stackoverflow.com/questions/16161343/without-exiting-from-the-ssh-tunnel-open-new-terminal