Broken pipe with os.popen3()

C

Christoph Krammer

Hello everybody,

I try to use an external OCR tool to convert some binary image data to
text. The image is in one variable, the text should be converted to
another. I use the following code:

(si, so, se) = os.popen3('ocrad')
si.write(frame)
si.close()
messagetext += so.read()

This code leads to a broken pipe error. I think this is because of the
command already writing data to stdout after getting the first part of
the input. But when I change the order of the code lines, i.e. opening
the reading pipe so before writing to si, the program hangs, because
no data is written to stdout before the first bytes are written to
stdin. Any idea how to solve this issue? How do I read and write
simultaneously?

Thanks in advance,
Christoph
 
T

Thomas Guettler

Christoph said:
Hello everybody,

I try to use an external OCR tool to convert some binary image data to
text. The image is in one variable, the text should be converted to
another. I use the following code:

(si, so, se) = os.popen3('ocrad')
si.write(frame)
si.close()
messagetext += so.read()

If you use popen you should use *one* filehandle. The app
hangs because the buffer is full. See
http://docs.python.org/lib/popen2-flow-control.html
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top