By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,536 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,536 IT Pros & Developers. It's quick & easy.

Communicating with xterm

P: n/a
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
Jul 12 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.