From 5796b23810cc9703f59f59153def6856a81831c0 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 21 Dec 2018 16:22:32 +0100 Subject: [PATCH] call_helpers: Make default behaviour of subprocess_run compatible subprocess_run just calls call_and_capture which has different default settings (return text instead of bytes, split lines). However, subprocess_run should be a drop-in replacement of the python3.5 subprocess.run function, so should behave the same way. This little trick fixed e.g. calls to "get_cnf -j" called from cnfvar.py on python 3.3 (current intra2net system version) --- src/call_helpers.py | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/call_helpers.py b/src/call_helpers.py index fbd2128..ca4e98f 100644 --- a/src/call_helpers.py +++ b/src/call_helpers.py @@ -124,14 +124,16 @@ class CalledProcessError(Exception): self.cmd, self.returncode) -def subprocess_run(args, check=True, shell=True): +def subprocess_run(args, check=True, shell=True, universal_newlines=False): """ Backported minimal function from the py3.5+ subprocess module. All arguments are equivalent to the formal subprocess module. """ command = args if isinstance(args, str) else " ".join(args) - status, stdout, stderr = call_and_capture(command, shell=shell) + status, stdout, stderr = \ + call_and_capture(command, shell=shell, split_lines=False, + universal_newlines=universal_newlines) if check and status != 0: raise CalledProcessError(status, args, stderr=stderr) else: -- 1.7.1