@@ -125,7 +125,7 @@ def run_htrun(cmd, verbose):
125
125
htrun_failure_line = re .compile ('\[RXD\] (:\d+::FAIL: .*)' )
126
126
127
127
for line in iter (p .stdout .readline , b'' ):
128
- decoded_line = line .decode (' utf-8' , 'ignore' )
128
+ decoded_line = line .decode (" utf-8" , "replace" )
129
129
htrun_output += decoded_line
130
130
# When dumping output to file both \r and \n will be a new line
131
131
# To avoid this "extra new-line" we only use \n at the end
@@ -135,7 +135,20 @@ def run_htrun(cmd, verbose):
135
135
gt_logger .gt_log_err (test_error .group (1 ))
136
136
137
137
if verbose :
138
- sys .stdout .write (decoded_line .rstrip () + '\n ' )
138
+ output = decoded_line .rstrip () + '\n '
139
+ try :
140
+ # Try to output decoded unicode. Should be fine in most Python 3
141
+ # environments.
142
+ sys .stdout .write (output )
143
+ except UnicodeEncodeError :
144
+ try :
145
+ # Try to encode to unicode bytes and let the terminal handle
146
+ # the decoding. Some Python 2 and OS combinations handle this
147
+ # gracefully.
148
+ sys .stdout .write (output .encode ("utf-8" ))
149
+ except TypeError :
150
+ # Fallback to printing just ascii characters
151
+ sys .stdout .write (output .encode ("ascii" , "replace" ).decode ("ascii" ))
139
152
sys .stdout .flush ()
140
153
141
154
# Check if process was terminated by signal
0 commit comments