execute_process: Improve stdout/stderr merging

Use the KWSys Process "MergeOutput" option to give the child process
the same pipe (or file) for both stdout and stderr.  This allows
natural merging of stdout and stderr together instead of merging
on arbitrary buffered read boundaries as before.
This commit is contained in:
Brad King
2015-05-07 14:40:38 -04:00
parent 31c218e6e1
commit f65bb82f36
11 changed files with 82 additions and 6 deletions
+19 -5
View File
@@ -255,7 +255,7 @@ bool cmExecuteProcessCommand
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
// Check the output variables.
bool merge_output = (output_variable == error_variable);
bool merge_output = false;
if(!input_file.empty())
{
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDIN, input_file.c_str());
@@ -267,8 +267,23 @@ bool cmExecuteProcessCommand
}
if(!error_file.empty())
{
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDERR,
error_file.c_str());
if (error_file == output_file)
{
merge_output = true;
}
else
{
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDERR,
error_file.c_str());
}
}
if (!output_variable.empty() && output_variable == error_variable)
{
merge_output = true;
}
if (merge_output)
{
cmsysProcess_SetOption(cp, cmsysProcess_Option_MergeOutput, 1);
}
// Set the timeout if any.
@@ -289,8 +304,7 @@ bool cmExecuteProcessCommand
while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p))
{
// Put the output in the right place.
if((p == cmsysProcess_Pipe_STDOUT && !output_quiet) ||
(p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output))
if (p == cmsysProcess_Pipe_STDOUT && !output_quiet)
{
if(output_variable.empty())
{