From b9894596c05f1cdce671dd6822ddc0308a93eb0d Mon Sep 17 00:00:00 2001 From: Priyam Sahoo <42550351+priyamsahoo@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:50:43 +0530 Subject: [PATCH] Add env variable to remove color from command result stdout (#579) * add env variable to remove color from command result stdout * remove color (proper way) --- src/utils/misc.ts | 1 + test/index.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 2ec74fb1..fe43603d 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -50,6 +50,7 @@ export function withInterpreter( let command = `${executable} ${args}`; // base case const newEnv = Object.assign({}, process.env, { + NO_COLOR: "1", // ensure none of the output produce color characters ANSIBLE_FORCE_COLOR: "0", // ensure output is parseable (no ANSI) PYTHONBREAKPOINT: "0", // We want to be sure that python debugger is never // triggered, even if we mistakenly left a breakpoint() there while diff --git a/test/index.ts b/test/index.ts index c29fa00e..6b3ac3fc 100644 --- a/test/index.ts +++ b/test/index.ts @@ -13,9 +13,14 @@ if (isWindows()) { process.exit(PRETEST_ERR_RC); } +// We don't require colors in the stdout of the command results. +process.env["NO_COLOR"] = "1"; + const command = "ansible-lint --version"; +const env = process.env; + try { - const result = execSync(command); + const result = execSync(command, { env: env }); console.info(`Detected: ${result}`); } catch (e) { console.error(`error: test requisites not met, '${command}' returned ${e}`);