mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-87901: Add encoding to os.popen (GH-92374)
This commit is contained in:
parent
926854e858
commit
2b563f1ad3
3 changed files with 9 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue