Issue combining gzip and subprocess

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jul 22 10:12:18 EDT 2009


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

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

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list