|
@@ -247,6 +247,12 @@ void cmSystemTools::Stdout(const char* s)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void cmSystemTools::Stderr(const char* s, int length)
|
|
|
|
|
+{
|
|
|
|
|
+ std::cerr.write(s, length);
|
|
|
|
|
+ std::cerr.flush();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void cmSystemTools::Stdout(const char* s, int length)
|
|
void cmSystemTools::Stdout(const char* s, int length)
|
|
|
{
|
|
{
|
|
|
if(s_StdoutCallback)
|
|
if(s_StdoutCallback)
|
|
@@ -577,7 +583,7 @@ std::vector<cmStdString> cmSystemTools::ParseArguments(const char* command)
|
|
|
bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
|
std::string* output ,
|
|
std::string* output ,
|
|
|
int* retVal , const char* dir ,
|
|
int* retVal , const char* dir ,
|
|
|
- bool verbose ,
|
|
|
|
|
|
|
+ OutputOption outputflag ,
|
|
|
double timeout )
|
|
double timeout )
|
|
|
{
|
|
{
|
|
|
std::vector<const char*> argv;
|
|
std::vector<const char*> argv;
|
|
@@ -599,38 +605,54 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
|
{
|
|
{
|
|
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
cmsysProcess_SetTimeout(cp, timeout);
|
|
cmsysProcess_SetTimeout(cp, timeout);
|
|
|
cmsysProcess_Execute(cp);
|
|
cmsysProcess_Execute(cp);
|
|
|
|
|
|
|
|
std::vector<char> tempOutput;
|
|
std::vector<char> tempOutput;
|
|
|
char* data;
|
|
char* data;
|
|
|
int length;
|
|
int length;
|
|
|
- if ( output || verbose )
|
|
|
|
|
|
|
+ int pipe;
|
|
|
|
|
+ if ( output || outputflag != OUTPUT_NONE )
|
|
|
{
|
|
{
|
|
|
- while(cmsysProcess_WaitForData(cp, &data, &length, 0))
|
|
|
|
|
- {
|
|
|
|
|
- if(output || verbose)
|
|
|
|
|
|
|
+ while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
|
|
|
{
|
|
{
|
|
|
- // Translate NULL characters in the output into valid text.
|
|
|
|
|
- // Visual Studio 7 puts these characters in the output of its
|
|
|
|
|
- // build process.
|
|
|
|
|
- for(int i=0; i < length; ++i)
|
|
|
|
|
|
|
+ if(output || outputflag != OUTPUT_NONE)
|
|
|
{
|
|
{
|
|
|
- if(data[i] == '\0')
|
|
|
|
|
|
|
+ // Translate NULL characters in the output into valid text.
|
|
|
|
|
+ // Visual Studio 7 puts these characters in the output of its
|
|
|
|
|
+ // build process.
|
|
|
|
|
+ for(int i=0; i < length; ++i)
|
|
|
{
|
|
{
|
|
|
- data[i] = ' ';
|
|
|
|
|
|
|
+ if(data[i] == '\0')
|
|
|
|
|
+ {
|
|
|
|
|
+ data[i] = ' ';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ( output )
|
|
|
|
|
+ {
|
|
|
|
|
+ tempOutput.insert(tempOutput.end(), data, data+length);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(outputflag != OUTPUT_NONE)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(outputflag == OUTPUT_MERGE)
|
|
|
|
|
+ {
|
|
|
|
|
+ cmSystemTools::Stdout(data, length);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if(pipe == cmsysProcess_Pipe_STDERR)
|
|
|
|
|
+ {
|
|
|
|
|
+ cmSystemTools::Stderr(data, length);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(pipe == cmsysProcess_Pipe_STDOUT)
|
|
|
|
|
+ {
|
|
|
|
|
+ cmSystemTools::Stdout(data, length);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if ( output )
|
|
|
|
|
- {
|
|
|
|
|
- tempOutput.insert(tempOutput.end(), data, data+length);
|
|
|
|
|
- }
|
|
|
|
|
- if(verbose)
|
|
|
|
|
- {
|
|
|
|
|
- cmSystemTools::Stdout(data, length);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
cmsysProcess_WaitForExit(cp, 0);
|
|
cmsysProcess_WaitForExit(cp, 0);
|
|
@@ -657,7 +679,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
|
|
|
{
|
|
{
|
|
|
const char* exception_str = cmsysProcess_GetExceptionString(cp);
|
|
const char* exception_str = cmsysProcess_GetExceptionString(cp);
|
|
|
- if ( verbose )
|
|
|
|
|
|
|
+ if ( outputflag != OUTPUT_NONE )
|
|
|
{
|
|
{
|
|
|
std::cerr << exception_str << std::endl;
|
|
std::cerr << exception_str << std::endl;
|
|
|
}
|
|
}
|
|
@@ -670,7 +692,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
|
|
|
{
|
|
{
|
|
|
const char* error_str = cmsysProcess_GetErrorString(cp);
|
|
const char* error_str = cmsysProcess_GetErrorString(cp);
|
|
|
- if ( verbose )
|
|
|
|
|
|
|
+ if ( outputflag != OUTPUT_NONE )
|
|
|
{
|
|
{
|
|
|
std::cerr << error_str << std::endl;
|
|
std::cerr << error_str << std::endl;
|
|
|
}
|
|
}
|
|
@@ -683,7 +705,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
|
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
|
|
else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
|
|
|
{
|
|
{
|
|
|
const char* error_str = "Process terminated due to timeout\n";
|
|
const char* error_str = "Process terminated due to timeout\n";
|
|
|
- if ( verbose )
|
|
|
|
|
|
|
+ if ( outputflag != OUTPUT_NONE )
|
|
|
{
|
|
{
|
|
|
std::cerr << error_str << std::endl;
|
|
std::cerr << error_str << std::endl;
|
|
|
}
|
|
}
|
|
@@ -703,12 +725,12 @@ bool cmSystemTools::RunSingleCommand(
|
|
|
std::string* output,
|
|
std::string* output,
|
|
|
int *retVal,
|
|
int *retVal,
|
|
|
const char* dir,
|
|
const char* dir,
|
|
|
- bool verbose,
|
|
|
|
|
|
|
+ OutputOption outputflag,
|
|
|
double timeout)
|
|
double timeout)
|
|
|
{
|
|
{
|
|
|
if(s_DisableRunCommandOutput)
|
|
if(s_DisableRunCommandOutput)
|
|
|
{
|
|
{
|
|
|
- verbose = false;
|
|
|
|
|
|
|
+ outputflag = OUTPUT_NONE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
|
|
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
|
|
@@ -718,7 +740,7 @@ bool cmSystemTools::RunSingleCommand(
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
return cmSystemTools::RunSingleCommand(args, output,retVal,
|
|
return cmSystemTools::RunSingleCommand(args, output,retVal,
|
|
|
- dir, verbose, timeout);
|
|
|
|
|
|
|
+ dir, outputflag, timeout);
|
|
|
}
|
|
}
|
|
|
bool cmSystemTools::RunCommand(const char* command,
|
|
bool cmSystemTools::RunCommand(const char* command,
|
|
|
std::string& output,
|
|
std::string& output,
|