Windows: Encode child process output to internally-used encoding

Typically Windows applications (eg. MSVC compiler) use current console's
codepage for output to pipes so we need to encode that to our
internally-used encoding (`KWSYS_ENCODING_DEFAULT_CODEPAGE`).
This commit is contained in:
Dāvis Mosāns
2016-11-01 20:29:17 +02:00
parent 96103972ea
commit 595feb3234
9 changed files with 196 additions and 26 deletions

View File

@@ -6,6 +6,7 @@
#include <stdio.h>
#include "cmMakefile.h"
#include "cmProcessOutput.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
@@ -214,17 +215,28 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
int length;
char* data;
int p;
cmProcessOutput processOutput;
std::string strdata;
while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) {
if (verbose) {
cmSystemTools::Stdout(data, length);
processOutput.DecodeText(data, length, strdata);
cmSystemTools::Stdout(strdata.c_str(), strdata.size());
}
output.append(data, length);
}
}
if (verbose) {
processOutput.DecodeText(std::string(), strdata);
if (!strdata.empty()) {
cmSystemTools::Stdout(strdata.c_str(), strdata.size());
}
}
// All output has been read. Wait for the process to exit.
cmsysProcess_WaitForExit(cp, CM_NULLPTR);
processOutput.DecodeText(output, output);
// Check the result of running the process.
std::string msg;