Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1 | From 057872fa40e061100d61117cee5c3413ef2e40fc Mon Sep 17 00:00:00 2001 |
| 2 | From: Mingli Yu <mingli.yu@windriver.com> |
| 3 | Date: Thu, 20 Jan 2022 15:18:20 +0800 |
| 4 | Subject: [PATCH] setupinfo.py: check the return value |
| 5 | |
| 6 | Use the return value altogether to check the subprocess execute |
| 7 | successfully or not as in some case it will print some noise |
| 8 | message though run successfully as below. |
| 9 | |
| 10 | # python |
| 11 | Python 3.8.10 (default, Nov 26 2021, 20:14:08) |
| 12 | [GCC 9.3.0] on linux |
| 13 | Type "help", "copyright", "credits" or "license" for more information. |
| 14 | >>> import subprocess |
| 15 | >>> cmd = "pkg-config --modversion libxml-2.0" |
| 16 | >>> p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 17 | >>> stdout_data, errors = p.communicate() |
| 18 | >>> print(stdout_data) |
| 19 | b'2.9.12\n' |
| 20 | >>> print(errors) |
| 21 | b'do_ypcall: clnt_call: RPC: Unable to send; errno = Network is unreachable\n' |
| 22 | >>> |
| 23 | |
| 24 | Upstream-Status: Submitted [https://github.com/lxml/lxml/pull/336] |
| 25 | |
| 26 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> |
| 27 | --- |
| 28 | setupinfo.py | 2 +- |
| 29 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 30 | |
| 31 | diff --git a/setupinfo.py b/setupinfo.py |
| 32 | index 8c2a36fb..c1247c6d 100644 |
| 33 | --- a/setupinfo.py |
| 34 | +++ b/setupinfo.py |
| 35 | @@ -365,7 +365,7 @@ def run_command(cmd, *args): |
| 36 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 37 | stdout_data, errors = p.communicate() |
| 38 | |
| 39 | - if errors: |
| 40 | + if p.returncode != 0 and errors: |
| 41 | return '' |
| 42 | return decode_input(stdout_data).strip() |
| 43 | |
| 44 | -- |
| 45 | 2.17.1 |
| 46 | |