From 1cc3b46d32292c7dcd6b4b8aeb66b7a766af6d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 15 Jun 2022 17:13:14 +0200 Subject: [PATCH] cppcheckdata.py: better handling when subprocess call fails --- addons/cppcheckdata.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index f56081923..bba9c049b 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -1391,7 +1391,11 @@ 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 + if sys.platform == 'win32': + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid) + comm = p.communicate() + if p.returncode == 0: + return comm[0].decode(encoding='utf-8', errors='ignore') + return comm[1].decode(encoding='utf-8', errors='ignore')