Skip to content

Commit 2c6dac9

Browse files
committed
[incrParse] Encode Unicode characters in command output if stdout doesn't support Unicode
In verbose mode incrparse/test_util.py outputs the commands it executes to stdout. Since these commands contain Unicode emojis, it fails if stdout doesn't support Unicode. In these cases, encode the Unicode characters to their escape sequence. rdar://92047111
1 parent c254623 commit 2c6dac9

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)