Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/coreclr/scripts/jitutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,22 @@ def set_pipeline_variable(name, value):
##
################################################################################

def decode_string(str_to_decode):
def decode_and_print(str_to_decode):
"""Decode a UTF-8 encoded bytes to string.

Args:
str_to_decode (byte stream): Byte stream to decode

Returns:
String output. If there any encoding/decoding errors, it will replace it with
UnicodeEncodeError.
String output. If there any encoding/decoding errors, it will not print anything
and return an empty string.
"""
output = ''
try:
output = str_to_decode.decode("utf-8", errors='replace')
except UnicodeEncodeError:
output = "UnicodeEncodeError"
except UnicodeDecodeError:
output = "UnicodeDecodeError"
return output
print(output)
finally:
return output

def run_command(command_to_run, _cwd=None, _exit_on_fail=False, _output_file=None):
""" Runs the command.
Expand Down Expand Up @@ -138,15 +137,14 @@ def run_command(command_to_run, _cwd=None, _exit_on_fail=False, _output_file=Non
if proc.poll() is not None:
break
if output:
output_str = decode_string(output.strip())
print(output_str)
output_str = decode_and_print(output.strip())
of.write(output_str + "\n")
else:
command_stdout, command_stderr = proc.communicate()
if len(command_stdout) > 0:
print(decode_string(command_stdout))
decode_and_print(command_stdout)
if len(command_stderr) > 0:
print(decode_string(command_stderr))
decode_and_print(command_stderr)

return_code = proc.returncode
if _exit_on_fail and return_code != 0:
Expand Down