summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-05-06 05:48:36 (GMT)
committerGitHub <noreply@github.com>2022-05-06 05:48:36 (GMT)
commit2b563f1ad31af0bb0a9947e6f1f76e58dbf170f0 (patch)
treecb37aa7795169c2b095ebbc7f67316ff0aca215c /Lib/os.py
parent926854e8583125eaadd2a19b580c09d7c12389e9 (diff)
downloadcpython-2b563f1ad31af0bb0a9947e6f1f76e58dbf170f0.zip
cpython-2b563f1ad31af0bb0a9947e6f1f76e58dbf170f0.tar.gz
cpython-2b563f1ad31af0bb0a9947e6f1f76e58dbf170f0.tar.bz2
gh-87901: Add encoding to os.popen (GH-92374)
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 4626d1f..67662ca 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -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,