Decode text properly on foreign language systems.
Decode text properly on foreign language systems.
1.1 --- a/ambuild2/util.py Sat Feb 08 21:09:50 2014 -0800
1.2 +++ b/ambuild2/util.py Sat Feb 15 12:05:52 2014 -0800
1.3 @@ -88,8 +88,8 @@
1.4
1.5 def WaitForProcess(process):
1.6 out, err = process.communicate()
1.7 - process.stdoutText = out.decode('utf8')
1.8 - process.stderrText = err.decode('utf8')
1.9 + process.stdoutText = DecodeConsoleText(out)
1.10 + process.stderrText = DecodeConsoleText(err)
1.11 return process.returncode
1.12
1.13 def CreateProcess(argv, executable = None):
1.14 @@ -364,6 +364,12 @@
1.15 ConsoleNormal)
1.16 raise
1.17
1.18 +def DecodeConsoleText(text):
1.19 + try:
1.20 + return text.decode(locale.getpreferredencoding(), 'replace')
1.21 + except:
1.22 + return text.decode('utf8')
1.23 +
1.24 def WriteEncodedText(fd, text):
1.25 if not hasattr(fd, 'encoding') or fd.encoding == None:
1.26 text = text.encode(locale.getpreferredencoding(), 'replace')