New submission from Michael Herrmann <[email protected]>:
Consider the following:
import gzip
import subprocess
with gzip.open('test.gz', 'wb') as f:
subprocess.run(['echo', 'hi'], stdout=f)
with gzip.open('test.gz', 'rb') as f:
print(f.read())
I'd expect "hi" to appear in my console. Instead, I'm getting "OSError: Not a
gzipped file (b'hi')". I am attaching test.gz.
This appears for me on Debian 10 / Python 3.7 and Debian 11 / Python 3.9. I
have not yet tested on other OSs and Python versions.
The reason why I expect the above to work is that the subprocess documentation
states that the stdout parameter may be "an existing file object" and that on
the other hand the documentation for gzip.open(...) states that it returns a
file object.
Maybe this is related to #40885?
----------
files: test.gz
messages: 404853
nosy: mherrmann.at
priority: normal
severity: normal
status: open
title: Gzipping subprocess output produces invalid .gz file
type: behavior
versions: Python 3.7, Python 3.9
Added file: https://bugs.python.org/file50391/test.gz
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45585>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com