aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-02-06 11:26:36 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-02-17 23:45:59 +0530
commitc07b34ac6a47b1c06aa7538f3bc2fb05db6b9a22 (patch)
tree5686bf36d1422a44a87b312fd41eb7eaf040d65e
parent903cdc172fb51d562efd68d25e79fd2465c898a6 (diff)
downloadmeson-c07b34ac6a47b1c06aa7538f3bc2fb05db6b9a22.zip
meson-c07b34ac6a47b1c06aa7538f3bc2fb05db6b9a22.tar.gz
meson-c07b34ac6a47b1c06aa7538f3bc2fb05db6b9a22.tar.bz2
mesonlib: Set stdin to DEVNULL for all programs run by us
Otherwise there's a high likelihood that some program run by us will mess up the console settings and break ANSI colors. F.ex., running `uname` in the Visual Studio 2019 x86 developer prompt using `run_command()` does this.
-rw-r--r--mesonbuild/mesonlib.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 85d883b..461f24c 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1080,6 +1080,10 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None,
**kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]:
import locale
encoding = locale.getpreferredencoding()
+ # Redirect stdin to DEVNULL otherwise the command run by us here might mess
+ # up the console and ANSI colors will stop working on Windows.
+ 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,