mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-09 08:46:06 +00:00

By default in Python 3, check_output() returns a program's output as an encoded byte sequence. This means it returns a Py3 `bytes` object, which cannot be compared to a string since it's a different fundamental type. Although it might not be correct from a purist standpoint, from a practical one we can assume that all output is encoded in the default locale, in which case using universal_newlines=True will decode it according to the current locale. Anyway, universal_newlines also has the nice behavior that it converts \r\n to \n on Windows platforms so this makes parsing code easier, should we need that. So it seems like a win/win. llvm-svn: 252025
20 lines
576 B
Python
20 lines
576 B
Python
import six
|
|
|
|
if six.PY2:
|
|
import commands
|
|
get_command_output = commands.getoutput
|
|
get_command_status_output = commands.getstatusoutput
|
|
|
|
cmp_ = cmp
|
|
else:
|
|
def get_command_status_output(command):
|
|
try:
|
|
import subprocess
|
|
return (0, subprocess.check_output(command, shell=True, universal_newlines=True))
|
|
except subprocess.CalledProcessError as e:
|
|
return (e.returncode, e.output)
|
|
|
|
def get_command_output(command):
|
|
return get_command_status_output(command)[1]
|
|
|
|
cmp_ = lambda x, y: (x > y) - (x < y) |