Communicating with xterm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roy, Anirban (Anirban)

    #1

    Communicating with xterm

    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(slav e)
    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
Working...