mercurial/utils/procutil.py
changeset 45148 a37f290a7124
parent 45103 a5fa2761a6cd
child 45786 37c65704869d
child 46019 fdd54a876213
--- a/mercurial/utils/procutil.py	Fri Jul 17 00:37:33 2020 +0200
+++ b/mercurial/utils/procutil.py	Fri Jul 17 03:28:52 2020 +0200
@@ -119,18 +119,25 @@
     # a silly wrapper to make a bytes stream backed by a unicode one.
     stdin = sys.stdin.buffer
     stdout = _make_write_all(sys.stdout.buffer)
+    stderr = _make_write_all(sys.stderr.buffer)
+    if pycompat.iswindows:
+        # Work around Windows bugs.
+        stdout = platform.winstdout(stdout)
+        stderr = platform.winstdout(stderr)
     if isatty(stdout):
         # The standard library doesn't offer line-buffered binary streams.
         stdout = make_line_buffered(stdout)
-    stderr = _make_write_all(sys.stderr.buffer)
 else:
     # Python 2 uses the I/O streams provided by the C library.
     stdin = sys.stdin
     stdout = sys.stdout
+    stderr = sys.stderr
+    if pycompat.iswindows:
+        # Work around Windows bugs.
+        stdout = platform.winstdout(stdout)
+        stderr = platform.winstdout(stderr)
     if isatty(stdout):
         if pycompat.iswindows:
-            # Work around size limit when writing to console.
-            stdout = platform.winstdout(stdout)
             # The Windows C runtime library doesn't support line buffering.
             stdout = make_line_buffered(stdout)
         else:
@@ -138,7 +145,6 @@
             # replace a TTY destined stdout with a pipe destined stdout (e.g.
             # pager), we want line buffering.
             stdout = os.fdopen(stdout.fileno(), 'wb', 1)
-    stderr = sys.stderr
 
 
 findexe = platform.findexe