[Q] Problem with popen2

Oliver Hofmann a2619725 at uni-koeln.de
Wed May 16 04:34:14 EDT 2001


'lo everyone!


Got a problem figuring out how the 'popen2' file objects work. What
I was trying to do is fetching a file from an FTP server, uncompressing
it and passing it to another function.

For the first attempt I used ftplib's retrbinary(), allowing me to 
pass chuncks of data to zlib's decompressobj and uncompress it instead
of having to open a file, storing it on the harddisk, then reading it
again.

Unfortunately, zlib does not support the compress - format (*.Z); so 
this did not work out. I've then tried popen2 and ran into a problem,
sample code follows:

---
import popen2

zip_out, zip_in = popen2.popen2('compress -dc')

file = open('./dummy.Z', 'rb')

zip_in.write(file.read())

file.close()
zip_in.close()

print zip_out.read()
---

This works fine if the compressed file is very small (ie 2k), but
fails for larger files. It _seems_ that zip_in.write() waits for
an EOF which never arrives, so it gets stuck at that point.

Would someone be so kind to point out the error or refer me to 
some kind of documentation? Also, hints on how to solve this in 
a better way would be highly appreciated; don't like having to
use read() for a 100+ MB file :-/


Thanks,

    Oliver





More information about the Python-list mailing list