Help! pty interact with bash

Discussion in 'Python' started by est, Feb 18, 2008.

  1. est

    est Guest

    #!/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() ?
     
    est, Feb 18, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Evan Driscoll
    Replies:
    0
    Views:
    216
    Evan Driscoll
    Oct 24, 2012
  2. Evan Driscoll
    Replies:
    0
    Views:
    169
    Evan Driscoll
    Oct 24, 2012
  3. Evan Driscoll
    Replies:
    0
    Views:
    196
    Evan Driscoll
    Oct 24, 2012
  4. David Hutto
    Replies:
    0
    Views:
    207
    David Hutto
    Oct 24, 2012
  5. David Hutto
    Replies:
    0
    Views:
    186
    David Hutto
    Oct 24, 2012
Loading...

Share This Page