pipe problems

Leonardo B Lopes leo at iems.nwu.edu
Wed Mar 7 19:55:34 EST 2001


I use a program that doesn't have readline compiled in. So I figured, it
would be easy to add a python wrapper around it. So I wrote the wrapper,
using 'cat' as a test command. With 'cat' it works fine. But when I try
using another program, such as 'python', the program just hangs at
readline(). Anybody know how to accomplish this? Here is the code:

#!/usr/local/bin/python

import sys,os
import cmd

class Amplcmd(cmd.Cmd):

        def __init__(self):
                cmd.Cmd.__init__(self)
                self.cin,self.cout = os.popen2('/usr/local/bin/python')

        def default(self,line):
                self.cin.write(line+'\n')
                self.cin.flush()
                self.cout.flush()
                print self.cout.readline(),

        def do_EOF(self,line):
                sys.exit()

mycmd = Amplcmd() 
mycmd.cmdloop()



-- 
=======================================================================
Leonardo B. Lopes                                      leo at iems.nwu.edu 
Ph.D. Student                                             (847)491-8470
IEMS - Northwestern University             http://www.iems.nwu.edu/~leo



More information about the Python-list mailing list