1

I am trying to send commands to the Vte terminal but I keep getting the same error. Also, I could not find any other working examples on the internet. Since my code is not complete at the moment, I am showing you an example from stackoverflow. It gives the same error.

Error message :

File "~/basic-terminal/terminal.py", line 52, in InputToTerm
    self.terminal.feed_child(self.command, length)
TypeError: Vte.Terminal.feed_child() takes exactly 2 arguments (3 given)

The code :

from gi.repository import Gtk, GObject, Vte
#GObject is not required. I just import it everywhere just in case.
#Gtk, Vte, and GLib are required.
from gi.repository import GLib
import os
#os.environ['HOME'] helps to keep from hard coding the home string.
#os is not required unless you want that functionality.

class TheWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="inherited cell renderer")
        self.set_default_size(600, 300)
        self.terminal     = Vte.Terminal()
        self.terminal.fork_command_full(
                Vte.PtyFlags.DEFAULT, #default is fine
                os.environ['HOME'], #where to start the command?
                ["/bin/sh"], #where is the emulator?
                [], #it's ok to leave this list empty
                GLib.SpawnFlags.DO_NOT_REAP_CHILD,
                None, #at least None is required
                None,
                )
        #Set up a button to click and run a demo command
        self.button = Gtk.Button("Do The Command")
        #To get the command to automatically run
        #a newline(\n) character is used at the end of the
        #command string.
        self.command = "echo \"Sending this command to a virtual terminal.\"\n"
        command = Gtk.Label("The command: "+self.command)
        self.button.connect("clicked", self.InputToTerm)
        #end demo command code

        #set up the interface
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(self.button, False, True, 0)
        box.pack_start(command, False, True, 1)
        #a scroll window is required for the terminal
        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)

    def InputToTerm(self, clicker):
        #get the command when the button is clicked
        length = len(self.command)
        #A length is not required but is the easiest mechanism.
        #Otherwise the command must be null terminated.
        #Feed the command to the terminal.
        self.terminal.feed_child(self.command, length)


win = TheWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

What can i do ? Why am I constantly getting this error ?

  • 1
    Maybe because of this one **takes exactly 2 arguments (3 given)**? – Michi Aug 19 '20 at 08:14
  • Yes, that's the problem. I'm only giving 2 arguments. – Zeki Ahmet Bayar Aug 19 '20 at 08:17
  • Can you double check your code and make sure that you've copied the line that giving the error into the question because as it stands it's impossible to tell what's wrong. Your code clearly shows only two arguments are being passed to `feed_child` but the error message equally clearly shows that the system thinks there are three. – ChrisF Aug 19 '20 at 08:23
  • Yes, you are right. Sorry for not writing the code here. I changed the question. Can you look again? – Zeki Ahmet Bayar Aug 19 '20 at 08:28

1 Answers1

1

solved the problem. the command has changed. You can also solve your problem this way :)

self.terminal.feed_child(self.command.encode("utf-8"))