I'm using the following python code to embed a terminal window (from Ubuntu Linux) in a Tkinter window. I would like give the command 'sh kBegin' in the window automatically when the terminal window starts:
from Tkinter import *
from os import system as cmd
root = Tk()
termf = Frame(root, height=800, width=1000)
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
cmd('xterm -into %d -geometry 160x50 -sb &' % wid)
root.mainloop()
Pseudo:
cmd('xterm -into %d -geometry 160x50 -sb &' % wid)
embedded_terminal('sh kBegin')
# EMBEDDED TERMINAL DISPLAYS OUTPUT OF sh kBegin##
How would I get this working?
You can interact with a shell by writing in the pseudo-terminal slave child. Here is a demo of how it could works. This answer is somewhat based on an answer to Linux pseudo-terminals: executing string sent from one terminal in another.
The point is to get the pseudo-terminal used by xterm (through
tty
command) and redirect output and input of your method to this pseudo-terminal file. For instancels < /dev/pts/1 > /dev/pts/1 2> /dev/pts/1
Note that
os.system
is not recommended, especially for&
instructions. Seesuprocess
module).cd
have no effect, as well as context of the xterm (cd
in the xterm)