pipe problems

Leonardo B Lopes leo at iems.nwu.edu
Thu Mar 8 14:27:18 EST 2001


Werner Schiendl wrote:
> 
> If there is no data to read, readline it will block for such to become
> available.
> I don't think that cout.flush() is of any use, btw.

When I tried the program with 'cat', it only worked if I used
cout.flush(). But maybe it doesn't work in general. My guess is that
this call is the crux of the problem. 

> Maybe I'm wrong, but I think data can only be flushed out by the sender of a
> pipe...
> Further, what's if the program prints out something in between, or more than
> 1 line?

That is something I'll deal with at a later point, when I get the basic
stuff working. I have the impression there is something about pipes that
I don't understand correctly.

Thanks,
Leo.

> 
> Maybe you can do the reading in a seperate thread.
> Alternatively you can try to find out if there _is_ sth you can read.
> 
> hth
> werner
> 
> Leonardo B Lopes <leo at iems.nwu.edu> wrote in message
> news:3AA6D886.4DD8D3A4 at iems.nwu.edu...
> > 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

-- 
=======================================================================
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