我正在使用python 2.6.4,並發現我無法像我希望的那樣對子進程使用gzip。這說明了一個問題:這裏是什麼樣子裏面少python中的Gzip和子進程'stdout
它看起來像它放在標準輸出爲文本,然後放入一個空的gzip文件
May 17 18:05:36> python
Python 2.6.4 (r264:75706, Mar 10 2010, 14:41:19)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gzip
>>> import subprocess
>>> fh = gzip.open("tmp","wb")
>>> subprocess.Popen("echo HI", shell=True, stdout=fh).wait()
0
>>> fh.close()
>>>
[2]+ Stopped python
May 17 18:17:49> file tmp
tmp: data
May 17 18:17:53> less tmp
"tmp" may be a binary file. See it anyway?
May 17 18:17:58> zcat tmp
zcat: tmp: not in gzip format
。事實上,如果我刪除「嗨\ n」,然後我得到這樣的:
May 17 18:22:34> file tmp
tmp: gzip compressed data, was "tmp", last modified: Mon May 17 18:17:12 2010, max compression
這到底是怎麼回事?
UPDATE: 這較早前的問題是問同樣的事情:與subprocess
,唯一真正的文件Can I use an opened gzip file with Popen in Python?
我想我是通過gzip管道然後。 – 2010-05-17 22:53:03