[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Help! pty interact with bash

est

2/18/2008 3:03:00 AM

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