Help! pty interact with bash

est electronixtar at gmail.com
Sun Feb 17 22:03:22 EST 2008


#!/usr/bin/env python
import os, pty, time

class pty_Popen:
    def __init__ (self, command, *args):
        self.pid, self.fd = pty.fork ()
        if self.pid == 0:
            os.execv (command, command, args)
        else:
            pass

    def read (self, max_read):
        return os.read (self.fd, max_read)

    def write (self, text):
        return os.write (self.fd, text)

p=pty_Popen("/bin/bash")
p.write("ls --color=always\nexit\n")
print p.read(1024)

I am implementing a wrapper for linux shells with codes above.
This is not responding right, anybody know why?

ps How can I tell which output is stdout or stderr in os.read() ?



More information about the Python-list mailing list