diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index f3c07591f..e09d123b9 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1084,10 +1084,15 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
     if 'stdin' not in kwargs:
         kwargs['stdin'] = subprocess.DEVNULL
     if sys.version_info < (3, 6) or not sys.stdout.encoding or encoding.upper() != 'UTF-8':
-        return Popen_safe_legacy(args, write=write, stdout=stdout, stderr=stderr, **kwargs)
-    p = subprocess.Popen(args, universal_newlines=True, close_fds=False,
-                         stdout=stdout, stderr=stderr, **kwargs)
-    o, e = p.communicate(write)
+        p, o, e = Popen_safe_legacy(args, write=write, stdout=stdout, stderr=stderr, **kwargs)
+    else:
+        p = subprocess.Popen(args, universal_newlines=True, close_fds=False,
+                             stdout=stdout, stderr=stderr, **kwargs)
+        o, e = p.communicate(write)
+    # Sometimes the command that we run will call another command which will be
+    # without the above stdin workaround, so set the console mode again just in
+    # case.
+    mlog.setup_console()
     return p, o, e
 
 def Popen_safe_legacy(args: T.List[str], write: T.Optional[str] = None,