From b44a38bf7f9e0220ae8786a976fda38ce25b906b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 16 Jun 2022 14:07:14 +0200 Subject: [PATCH] cppcheckdata.py: fix cmd_output() function, handle errors better --- addons/cppcheckdata.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index f56081923..417d193e9 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -1391,7 +1391,10 @@ def get_path_premium_addon(): def cmd_output(cmd): - try: - return subprocess.check_output(cmd).strip().decode('ascii') - except subprocess.CalledProcessError as e: - return e.output + with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: + comm = p.communicate() + out = comm[0] + if p.returncode == 1 and len(comm[1]) > 2: + out = comm[1] + return out.decode(encoding='utf-8', errors='ignore') +