From: Christian Herdtweck Date: Fri, 21 Dec 2018 15:22:32 +0000 (+0100) Subject: call_helpers: Make default behaviour of subprocess_run compatible X-Git-Tag: v1.4~11^2~2 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=5796b23810cc9703f59f59153def6856a81831c0;p=pyi2ncommon 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) --- 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: