Skip to content

Commit 2d77a36

Browse files
authored
[system-health] Make run_command() Python 3-compliant (#6371)
Pass universal_newlines=True parameter to subprocess.Popen(); no longer use .encode('utf-8') on resulting stdout. This was missed in #5886 Note: I would prefer to use text=True instead of universal_newlines=True, as the former is an alias only available in Python 3 and is more understandable than the latter. However, Even though the setup.py file for this package only specifies Python 3, the LGTM tool finds other Python 2 code in the repo and validates the code as Python 2 code and alerts that text=True is an invalid parameter. Will stick with universal_newlines=True for now. Once all Python code in the repo has been converted to Python 3, I will change all universal_newlines=True to text=True.
1 parent a6907a7 commit 2d77a36

File tree

1 file changed

+2
-2
lines changed
  • src/system-health/health_checker

1 file changed

+2
-2
lines changed

src/system-health/health_checker/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def run_command(command):
88
:return: Output of the shell command.
99
"""
1010
try:
11-
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
12-
return process.communicate()[0].encode('utf-8')
11+
process = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
12+
return process.communicate()[0]
1313
except Exception:
1414
return None
1515

0 commit comments

Comments
 (0)