1.1 --- a/ambuild2/util.py Sat Feb 15 12:05:52 2014 -0800
1.2 +++ b/ambuild2/util.py Sat Feb 15 12:24:48 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 = DecodeConsoleText(out)
1.8 - process.stderrText = DecodeConsoleText(err)
1.9 + process.stdoutText = DecodeConsoleText(sys.stdout, process.stdout, out)
1.10 + process.stderrText = DecodeConsoleText(sys.stderr, process.stderr, err)
1.11 return process.returncode
1.12
1.13 def CreateProcess(argv, executable = None):
1.14 @@ -364,11 +364,23 @@
1.15 ConsoleNormal)
1.16 raise
1.17
1.18 -def DecodeConsoleText(text):
1.19 +def try_decode_with_pipe(pipe, text):
1.20 try:
1.21 - return text.decode(locale.getpreferredencoding(), 'replace')
1.22 + if hasattr(pipe, 'encoding') and pipe.encoding:
1.23 + return text.decode(pipe.encoding, 'replace')
1.24 except:
1.25 - return text.decode('utf8')
1.26 + return None
1.27 +
1.28 +def DecodeConsoleText(origin, pipe, text):
1.29 + result = try_decode_with_pipe(pipe, text)
1.30 + if result is None:
1.31 + result = try_decode_with_pipe(origin, text)
1.32 + if result is None:
1.33 + try:
1.34 + result = text.decode(locale.getpreferredencoding(), 'replace')
1.35 + except:
1.36 + result = text
1.37 + return result.encode('utf8')
1.38
1.39 def WriteEncodedText(fd, text):
1.40 if not hasattr(fd, 'encoding') or fd.encoding == None: