gh-87901: Add encoding to os.popen (GH-92374)

This commit is contained in:
Inada Naoki 2022-05-06 14:48:36 +09:00 committed by GitHub
parent 926854e858
commit 2b563f1ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -974,7 +974,7 @@ otherwise return -SIG, where SIG is the signal that killed it. """
# command in a shell can't be supported.
if sys.platform != 'vxworks':
# Supply os.popen()
def popen(cmd, mode="r", buffering=-1):
def popen(cmd, mode="r", buffering=-1, encoding=None):
if not isinstance(cmd, str):
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
if mode not in ("r", "w"):
@ -982,6 +982,7 @@ if sys.platform != 'vxworks':
if buffering == 0 or buffering is None:
raise ValueError("popen() does not support unbuffered streams")
import subprocess, io
encoding = io.text_encoding(encoding)
if mode == "r":
proc = subprocess.Popen(cmd,
shell=True, text=True,