Skip to content

Commit 7b826d6

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 11c3ff0 commit 7b826d6

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
@@ -25,7 +25,12 @@ def escapeCmdArg(arg):
2525
def run_command(cmd):
2626
if sys.version_info[0] < 3:
2727
cmd = list(map(lambda s: s.encode('utf-8'), cmd))
28-
print(' '.join([escapeCmdArg(arg) for arg in cmd]))
28+
cmdStr = ' '.join([escapeCmdArg(arg) for arg in cmd])
29+
if not sys.stdout.encoding.lower().startswith('utf'):
30+
# stdout doesn't support Unicode characters, encode them into an escape
31+
# sequence
32+
cmdStr = cmdStr.encode('utf-8')
33+
print(cmdStr)
2934
if sys.version_info[0] < 3 or platform.system() == 'Windows':
3035
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
3136
else:

0 commit comments

Comments
 (0)