diff options
author | Mingli-Yu <41617974+Mingli-Yu@users.noreply.github.com> | 2022-01-20 18:56:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 11:56:56 +0100 |
commit | 55f281565a455dcf77731d38ddd86284c3ca3e28 (patch) | |
tree | 5f097fae8d4606ce2e5045247d6f59405668a857 | |
parent | 5a5c7fb01d15af58def4bab2ba7b15c937042835 (diff) | |
download | python-lxml-55f281565a455dcf77731d38ddd86284c3ca3e28.tar.gz |
setupinfo.py: check the return value of subprocesses (GH-336)
Use the return value altogether to check the subprocess execute
successfully or not as in some case it will print some noise
message though run successfully as below.
# python
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmd = "pkg-config --modversion libxml-2.0"
>>> p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> stdout_data, errors = p.communicate()
>>> print(stdout_data)
b'2.9.12\n'
>>> print(errors)
b'do_ypcall: clnt_call: RPC: Unable to send; errno = Network is unreachable\n'
-rw-r--r-- | setupinfo.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/setupinfo.py b/setupinfo.py index 8c2a36fb..c1247c6d 100644 --- a/setupinfo.py +++ b/setupinfo.py @@ -365,7 +365,7 @@ def run_command(cmd, *args): stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout_data, errors = p.communicate() - if errors: + if p.returncode != 0 and errors: return '' return decode_input(stdout_data).strip() |