pipe problems

Werner Schiendl ws-news at gmx.at
Thu Mar 8 04:54:33 EST 2001


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.
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?

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





More information about the Python-list mailing list