Issue combining gzip and subprocess

Piet van Oostrum piet at
Wed Jul 22 17:50:03 EDT 2009

>>>>> Scott David Daniels <Scott.Daniels at Acm.Org> (SDD) schreef:

>SDD> Piet van Oostrum wrote:
>>> ...
>>> f =, 'w')
>>> proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE)
>>> while True:
>>> line = proc.stdout.readline()
>>> if not line: break
>>> f.write(line)
>>> f.close()

>SDD> Or even:
>SDD>     proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE)
>SDD>     with, 'w') as dest:
>SDD>         for line in iter(proc.stdout, ''):
>SDD>             f.write(line)

If it would work.

1) with gzip... is not supported in Python < 3.1
2) for line in iter(proc.stdout), i.e. no second argument.
3) dest <==> f should be the same identifier.

Lesson: if you post code either: 
- test it and copy verbatim from your test, or
- write a disclaimer 
Piet van Oostrum <piet at>
URL: [PGP 8DAE142BE17999C4]
Private email: piet at

More information about the Python-list mailing list