问题
I'm writing an application to connect to few Linux server via SSH, which using VTE terminal to make some operation on this server. To connect to this server I'm using bash expect command to provide password. I want to run this command instantly after VTE was run , but here I have some ugly behavior of VTE, command was printed twice to terminal, once before bash prompt, and second normal after bash prompt
echo Here command to connesc ssh
[drespondek@oc5045316303 ~]$ echo Here command to connesc ssh
Here command to connesc ssh
[drespondek@oc5045316303 ~]$
How I can fix this behavior in my app? I know that this was working as I expect when I add time.sleep(1), before command feed, but this is not a solution. Execution output whit time.sleep
[drespondek@oc5045316303 ~]$ echo Here command to connesc ssh
Here command to connesc ssh
[drespondek@oc5045316303 ~]$
Here is sample code how I use VTE
from gi.repository import Gtk, Vte, GLib
import os
import time
class TheWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="test vte terminal")
self.set_default_size(600, 300)
self.terminal = Vte.Terminal()
self.terminal.spawn_sync(
Vte.PtyFlags.DEFAULT,
os.environ['HOME'],
["/bin/bash"],
[],
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
None,
None,
)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
scroller = Gtk.ScrolledWindow()
scroller.set_hexpand(True)
scroller.set_vexpand(True)
scroller.add(self.terminal)
box.pack_start(scroller, False, True, 2)
self.add(box)
#time.sleep(1)
self.terminal.feed_child("echo Here command to connesc ssh \n", -1)
win = TheWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Anybody has some idea how I can do that without sleep option?
来源:https://stackoverflow.com/questions/49464926/pygobject-vte-terminal-command-printed-twice