Skip to content

Commit

Permalink
[system-health] Make run_command() Python 3-compliant (#6371)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jleveque authored and lguohan committed Jan 9, 2021
1 parent 7462850 commit 984c833
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/system-health/health_checker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def run_command(command):
:return: Output of the shell command.
"""
try:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
return process.communicate()[0].encode('utf-8')
process = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
return process.communicate()[0]
except Exception:
return None

Expand Down

0 comments on commit 984c833

Please sign in to comment.