From 724fb93afe8b8b4d8931e4221a90b63bce964061 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Mon, 24 May 2021 07:54:00 +0800 Subject: [PATCH] Separate output content from CMD with form feed The command "cls" will produce a '\f' (0x0c, page break or form feed) character. --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c87d7e0..08fd322 100644 --- a/index.js +++ b/index.js @@ -116,14 +116,18 @@ function main() { const vcvars = `"${findVcvarsall()}" ${args.join(' ')}` core.debug(`vcvars command-line: ${vcvars}`) - const old_environment = child_process.execSync(`set`, {shell: "cmd"}).toString().split('\r\n') - const new_environment = child_process.execSync(`${vcvars} && set`, {shell: "cmd"}).toString().split('\r\n') + const cmd_output_string = child_process.execSync(`set && cls && ${vcvars} && cls && set`, {shell: "cmd"}).toString() + const cmd_output_parts = cmd_output_string.split('\f') + + const old_environment = cmd_output_parts[0].split('\r\n') + const vcvars_output = cmd_output_parts[1].split('\r\n') + const new_environment = cmd_output_parts[2].split('\r\n') // If vsvars.bat is given an incorrect command line, it will print out // an error and *still* exit successfully. Parse out errors from output // which don't look like environment variables, and fail if appropriate. var failed = false - for (let line of new_environment) { + for (let line of vcvars_output) { if (line.match(/^\[ERROR.*\]/)) { failed = true // Don't print this particular line which will be confusing in output.