diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-24 19:50:15 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-24 22:06:28 +0200 |
| commit | b650ccda72102bf8581420cfa31f6c6eab67f65d (patch) | |
| tree | 6fec8abda9576ca0cbdda23fa85dbdf890eb6672 /kconfiglib.py | |
| parent | 27173d98e5bdb714e10b233d4fa650927d8bcc03 (diff) | |
Use universal newlines mode in $(shell) implementation
This prevents e.g. stray \r's in command output on Windows after
stripping trailing newlines.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index e5db25c..18baa83 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5639,14 +5639,26 @@ def _error_if_fn(kconf, args): return "" def _shell_fn(kconf, args): - stdout, stderr = subprocess.Popen( - args[1], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ).communicate() + # Use universal newlines mode to prevent e.g. stray \r's in command output + # on Windows - if not _IS_PY2: + if _IS_PY2: + # No decoding on Python 2 + stdout, stderr = subprocess.Popen( + args[1], shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True + ).communicate() + + else: + # Passing universal_newlines=True and/or 'encoding' on Python 3 turns + # on decoding of the output (bytes -> str), which might fail try: - stdout = stdout.decode(kconf._encoding) - stderr = stderr.decode(kconf._encoding) + stdout, stderr = subprocess.Popen( + args[1], shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True, encoding=kconf._encoding + ).communicate() except UnicodeDecodeError as e: _decoding_error(e, kconf._filename, kconf._linenr) |
