Skip to content

Commit ee7446f

Browse files
authored
Merge pull request #42525 from ahoppen/pr/encode-utf8-verbose-output
[incrParse] Encode Unicode characters in command output if stdout doesn't support Unicode
2 parents b4fa721 + 7b826d6 commit ee7446f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

utils/incrparse/test_util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ def escapeCmdArg(arg):
2323
def run_command(cmd):
2424
if sys.version_info[0] < 3:
2525
cmd = list(map(lambda s: s.encode('utf-8'), cmd))
26-
print(' '.join([escapeCmdArg(arg) for arg in cmd]))
26+
cmdStr = ' '.join([escapeCmdArg(arg) for arg in cmd])
27+
if not sys.stdout.encoding.lower().startswith('utf'):
28+
# stdout doesn't support Unicode characters, encode them into an escape
29+
# sequence
30+
cmdStr = cmdStr.encode('utf-8')
31+
print(cmdStr)
2732
if sys.version_info[0] < 3 or platform.system() == 'Windows':
2833
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
2934
else:

0 commit comments

Comments
 (0)