Communicating with xterm
Roy, Anirban (Anirban)
anirbanroy at lucent.com
Wed Jul 12 01:03:31 EDT 2006
Hi,
I am new to Pythion world.
My Objective : I want to open an Xterm and try to send message to that
xterm. I dont want to use Expect script.
I have written a small program
import os
import commands
import pty
import re
import tty
(master,slave) = pty.openpty()
print "master = %d , slave = %d" %(master, slave)
paths = os.ttyname(slave)
print "paths = %s" %(paths)
p = re.compile('/(.*)/(.*)/(.*)')
m = p.split(paths)
cmd = '-S' + str(m[3]) + '/' + str(slave)
pid = os.fork()
if pid == 0:
os.setsid()
os.dup2(slave, 0)
os.dup2(slave, 1)
os.dup2(slave, 2)
os.close(master)
os.close(slave)
os.execv('/usr/openwin/bin/xterm',["xterm" , cmd])
else :
print "xterm pid = ", pid
while True:
os.write(master,"bash")
os.fsync(master)
os.write(master,"ls")
os.fsync(master)
os.write(master,"ls")
os.fsync(master)
os.write(master,"ls")
os.fsync(master)
os.write(master,"ls")
os.fsync(master)
data = os.read(0,20)
print "data is %s" %(data)
os.write(master,data)
But It is not working. Xterm window doesnot show the Shell prompt.
Can somebody please give some clue , how to progress .
Is there some example code for xterm communication with Python code.
regards
Anirban Roy
More information about the Python-list
mailing list