Help! pty interact with bash

E

est

#!/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() ?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top