Skip to content

Commit

Permalink
Use universal_newlines instead text arugment when Python version is o…
Browse files Browse the repository at this point in the history
…loder than 3.7.
  • Loading branch information
manateelazycat committed Nov 12, 2023
1 parent c6d0565 commit 29cc7a0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,19 @@ def get_emacs_func_result(method_name, *args):
def get_command_result(command_string, cwd):
import subprocess

process = subprocess.Popen(command_string, cwd=cwd, shell=True, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding="utf-8", errors="replace")
major, minor = sys.version_info[:2]

if major >= 3 and minor >= 7:
process = subprocess.Popen(command_string, cwd=cwd, shell=True, text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding="utf-8", errors="replace")
else:
process = subprocess.Popen(command_string, cwd=cwd, shell=True, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding="utf-8", errors="replace")

ret = process.wait()
return "".join((process.stdout if ret == 0 else process.stderr).readlines()).strip() # type: ignore
return "".join((process.stdout if ret == 0 else process.stderr).readlines()).strip()


def generate_request_id():
Expand Down

0 comments on commit 29cc7a0

Please sign in to comment.