[New-bugs-announce] [issue40885] Cannot pipe GzipFile into subprocess

Nehal Patel report at bugs.python.org
Fri Jun 5 20:56:53 EDT 2020

New submission from Nehal Patel <nehal.alum at gmail.com>:

The following code produces incorrect behavior:

with gzip.open("foo.gz") as gz:
    res = subprocess.run("cat", stdin=gz, capture_output=True)

the contents of res.stdout are identical to the contents of "foo.gz" 

It seems the subprocess somehow gets a hold of the underlying file descriptor pointing to the compressed file, and ends up being fed the compressed bytes.

components: IO
messages: 370804
nosy: Nehal Patel
priority: normal
severity: normal
status: open
title: Cannot pipe GzipFile into subprocess
type: behavior
versions: Python 3.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list