summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-04-20 19:36:57 (GMT)
committerBrad King <brad.king@kitware.com>2015-04-20 19:47:50 (GMT)
commit356c26ebdfa053f59b2932c78ae81cba3c872dc3 (patch)
tree48586b8e866870dc225395280ee8c1123998db65 /Source
parentf438cd373131b85dd71b1f902c56fb3584cf8f87 (diff)
downloadCMake-356c26ebdfa053f59b2932c78ae81cba3c872dc3.zip
CMake-356c26ebdfa053f59b2932c78ae81cba3c872dc3.tar.gz
CMake-356c26ebdfa053f59b2932c78ae81cba3c872dc3.tar.bz2
cmSystemTools: Teach RunSingleCommand to separate stdout and stderr
Extend the RunSingleCommand signature to capture stdout and stderr separately. Allow both to be captured to the same std::string to preserve existing behavior. Update all call sites to do this so that this refactoring does not introduce functional changes.
Diffstat (limited to 'Source')
-rw-r--r--Source/CPack/IFW/cmCPackIFWGenerator.cxx6
-rw-r--r--Source/CPack/WiX/cmCPackWIXGenerator.cxx3
-rw-r--r--Source/CPack/cmCPackDebGenerator.cxx6
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.cxx2
-rw-r--r--Source/CPack/cmCPackGenerator.cxx5
-rw-r--r--Source/CPack/cmCPackNSISGenerator.cxx12
-rw-r--r--Source/CPack/cmCPackOSXX11Generator.cxx6
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.cxx11
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx12
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx2
-rw-r--r--Source/cmBuildNameCommand.cxx2
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx2
-rw-r--r--Source/cmGlobalGenerator.cxx4
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx2
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx4
-rw-r--r--Source/cmQtAutoGenerators.cxx11
-rw-r--r--Source/cmSiteNameCommand.cxx2
-rw-r--r--Source/cmSystemTools.cxx63
-rw-r--r--Source/cmSystemTools.h7
-rw-r--r--Source/cmTryRunCommand.cxx2
-rw-r--r--Source/cmcldeps.cxx5
-rw-r--r--Source/cmcmd.cxx8
22 files changed, 109 insertions, 68 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
index 7f06e2d..0439ff6 100644
--- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
@@ -92,7 +92,8 @@ int cmCPackIFWGenerator::PackageFiles()
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Generate repository" << std::endl);
bool res = cmSystemTools::RunSingleCommand(
- ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
+ ifwCmd.c_str(), &output, &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
cmGeneratedFileStream ofs(ifwTmpFile.c_str());
@@ -176,7 +177,8 @@ int cmCPackIFWGenerator::PackageFiles()
int retVal = 1;
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Generate package" << std::endl);
bool res = cmSystemTools::RunSingleCommand(
- ifwCmd.c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0);
+ ifwCmd.c_str(), &output, &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
cmGeneratedFileStream ofs(ifwTmpFile.c_str());
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index 99eabf2..b3eb7b2 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -64,7 +64,8 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
std::string output;
int returnValue = 0;
- bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ bool status = cmSystemTools::RunSingleCommand(
+ command.c_str(), &output, &output,
&returnValue, 0, cmSystemTools::OUTPUT_NONE);
cmsys::ofstream logFile(logFileName.c_str(), std::ios::app);
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
index fcf4122..fa02a3b 100644
--- a/Source/CPack/cmCPackDebGenerator.cxx
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -466,7 +466,7 @@ int cmCPackDebGenerator::createDeb()
std::string output;
int retval = -1;
- int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
&retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0);
if ( !res || retval )
@@ -505,7 +505,7 @@ int cmCPackDebGenerator::createDeb()
cmd += "\"";
//std::string output;
//int retVal = -1;
- res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
&retval, toplevel.c_str(), this->GeneratorVerbose, 0);
if ( !res || retval )
{
@@ -553,7 +553,7 @@ int cmCPackDebGenerator::createDeb()
}
}
}
- res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
&retval, this->GetOption("WDIR"), this->GeneratorVerbose, 0);
if ( !res || retval )
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
index 5da9234..4c400d9 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.cxx
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -197,7 +197,7 @@ bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command,
bool result = cmSystemTools::RunSingleCommand(
command.str().c_str(),
- output,
+ output, output,
&exit_code,
0,
this->GeneratorVerbose,
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 2b18c41..e254e9a 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -290,7 +290,8 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
<< std::endl);
std::string output;
int retVal = 1;
- bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
+ bool resB = cmSystemTools::RunSingleCommand(
+ it->c_str(), &output, &output,
&retVal, 0, this->GeneratorVerbose, 0);
if ( !resB || retVal )
{
@@ -668,7 +669,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
int retVal = 1;
bool resB =
cmSystemTools::RunSingleCommand(buildCommand.c_str(),
- &output,
+ &output, &output,
&retVal,
installDirectory.c_str(),
this->GeneratorVerbose, 0);
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index fe6cc95..2de2bc4 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -324,7 +324,7 @@ int cmCPackNSISGenerator::PackageFiles()
<< std::endl);
std::string output;
int retVal = 1;
- bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output,
+ bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output,
&retVal, 0, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
@@ -430,8 +430,8 @@ int cmCPackNSISGenerator::InitializeInternal()
<< nsisCmd << std::endl);
std::string output;
int retVal = 1;
- bool resS = cmSystemTools::RunSingleCommand(nsisCmd.c_str(),
- &output, &retVal, 0, this->GeneratorVerbose, 0);
+ bool resS = cmSystemTools::RunSingleCommand(
+ nsisCmd.c_str(), &output, &output, &retVal, 0, this->GeneratorVerbose, 0);
cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)");
cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs");
if ( !resS || retVal ||
@@ -836,9 +836,9 @@ CreateComponentDescription(cmCPackComponent *component,
zipListFileName.c_str());
std::string output;
int retVal = -1;
- int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &retVal,
- dirName.c_str(),
- cmSystemTools::OUTPUT_NONE, 0);
+ int res = cmSystemTools::RunSingleCommand(
+ cmd.c_str(), &output, &output,
+ &retVal, dirName.c_str(), cmSystemTools::OUTPUT_NONE, 0);
if ( !res || retVal )
{
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx
index 313e08b..d533af8 100644
--- a/Source/CPack/cmCPackOSXX11Generator.cxx
+++ b/Source/CPack/cmCPackOSXX11Generator.cxx
@@ -180,9 +180,9 @@ int cmCPackOSXX11Generator::PackageFiles()
bool res = false;
while(numTries > 0)
{
- res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
- &retVal, 0,
- this->GeneratorVerbose, 0);
+ res = cmSystemTools::RunSingleCommand(
+ dmgCmd.str().c_str(), &output, &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
if ( res && !retVal )
{
numTries = -1;
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
index dfe35c9..880663f 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.cxx
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -378,9 +378,9 @@ int cmCPackPackageMakerGenerator::PackageFiles()
bool res = false;
while(numTries > 0)
{
- res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
- &retVal, 0, this->GeneratorVerbose,
- 0);
+ res = cmSystemTools::RunSingleCommand(
+ dmgCmd.str().c_str(), &output, &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
if ( res && !retVal )
{
numTries = -1;
@@ -657,8 +657,9 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char *command,
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
std::string output;
int retVal = 1;
- bool res = cmSystemTools::RunSingleCommand(command, &output, &retVal, 0,
- this->GeneratorVerbose, 0);
+ bool res = cmSystemTools::RunSingleCommand(
+ command, &output, &output,
+ &retVal, 0, this->GeneratorVerbose, 0);
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
<< std::endl);
if ( !res || retVal )
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index 7f9825c..d1e7e3a 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -709,7 +709,8 @@ int cmCTestScriptHandler::CheckOutSourceDir()
output = "";
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Run cvs: " << this->CVSCheckOut << std::endl);
- res = cmSystemTools::RunSingleCommand(this->CVSCheckOut.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(
+ this->CVSCheckOut.c_str(), &output, &output,
&retVal, this->CTestRoot.c_str(), this->HandlerVerbose,
0 /*this->TimeOut*/);
if (!res || retVal != 0)
@@ -789,7 +790,8 @@ int cmCTestScriptHandler::PerformExtraUpdates()
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run Update: "
<< fullCommand << std::endl);
- res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(
+ fullCommand.c_str(), &output, &output,
&retVal, cvsArgs[0].c_str(),
this->HandlerVerbose, 0 /*this->TimeOut*/);
if (!res || retVal != 0)
@@ -910,7 +912,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: "
<< command << std::endl);
- res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(
+ command.c_str(), &output, &output,
&retVal, this->BinaryDir.c_str(),
this->HandlerVerbose, 0 /*this->TimeOut*/);
@@ -956,7 +959,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: "
<< command << std::endl);
- res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
+ res = cmSystemTools::RunSingleCommand(
+ command.c_str(), &output, &output,
&retVal, this->BinaryDir.c_str(), this->HandlerVerbose,
0 /*this->TimeOut*/);
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index d778253..95cdf3b 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -1334,7 +1334,7 @@ int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
int retVal = 0;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " <<
*it << std::endl, this->Quiet);
- if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0,
+ if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, 0, &retVal, 0,
cmSystemTools::OUTPUT_MERGE
/*this->Verbose*/) || retVal != 0 )
{
diff --git a/Source/cmBuildNameCommand.cxx b/Source/cmBuildNameCommand.cxx
index 2a06574..2733d76 100644
--- a/Source/cmBuildNameCommand.cxx
+++ b/Source/cmBuildNameCommand.cxx
@@ -49,7 +49,7 @@ bool cmBuildNameCommand
if(this->Makefile->GetDefinition("UNIX"))
{
buildname = "";
- cmSystemTools::RunSingleCommand("uname -a", &buildname);
+ cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
if(!buildname.empty())
{
std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index 2aa4d93..24043af 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -1163,7 +1163,7 @@ cmExtraEclipseCDT4Generator::GetEclipsePath(const std::string& path)
#if defined(__CYGWIN__)
std::string cmd = "cygpath -m " + path;
std::string out;
- if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out))
+ if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out, &out))
{
return path;
}
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 4a9f628..4b0ef58 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1737,7 +1737,7 @@ int cmGlobalGenerator::Build(
output += cmSystemTools::PrintSingleCommand(cleanCommand);
output += "\n";
- if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
+ if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr, outputPtr,
&retVal, 0, outputflag, timeout))
{
cmSystemTools::SetRunCommandHideConsole(hideconsole);
@@ -1758,7 +1758,7 @@ int cmGlobalGenerator::Build(
output += makeCommandStr;
output += "\n";
- if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
+ if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr, outputPtr,
&retVal, 0, outputflag, timeout))
{
cmSystemTools::SetRunCommandHideConsole(hideconsole);
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 505914e..79a7914 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -1233,7 +1233,7 @@ std::string cmGlobalNinjaGenerator::ninjaVersion() const
std::string version;
std::string command = ninjaCmd() + " --version";
cmSystemTools::RunSingleCommand(command.c_str(),
- &version, 0, 0,
+ &version, 0, 0, 0,
cmSystemTools::OUTPUT_NONE);
return version;
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 8c37338..04befee 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -164,8 +164,8 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory
{
std::string out;
std::string::size_type pos;
- if(cmSystemTools::RunSingleCommand("xcode-select --print-path", &out, 0, 0,
- cmSystemTools::OUTPUT_NONE) &&
+ if(cmSystemTools::RunSingleCommand("xcode-select --print-path", &out, 0,
+ 0, 0, cmSystemTools::OUTPUT_NONE) &&
(pos = out.find(".app/"), pos != out.npos))
{
versionFile = out.substr(0, pos+5)+"Contents/version.plist";
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 3d5103f..329f9de 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -188,7 +188,7 @@ std::string cmQtAutoGenerators::ListQt5RccInputs(cmSourceFile* sf,
std::string output;
int retVal = 0;
- bool result = cmSystemTools::RunSingleCommand(command, &output,
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
&retVal, 0,
cmSystemTools::OUTPUT_NONE);
if (!result || retVal)
@@ -2196,7 +2196,8 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
std::string output;
int retVal = 0;
- bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
+ &retVal);
if (!result || retVal)
{
std::cerr << "AUTOGEN: error: process for " << mocFilePath <<" failed:\n"
@@ -2265,7 +2266,8 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
}
std::string output;
int retVal = 0;
- bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
+ &retVal);
if (!result || retVal)
{
std::cerr << "AUTOUIC: error: process for " << ui_output_file <<
@@ -2355,7 +2357,8 @@ bool cmQtAutoGenerators::GenerateQrc()
}
std::string output;
int retVal = 0;
- bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
+ &retVal);
if (!result || retVal)
{
std::cerr << "AUTORCC: error: process for " << rcc_output_file <<
diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx
index 20a61a0..e2970e5 100644
--- a/Source/cmSiteNameCommand.cxx
+++ b/Source/cmSiteNameCommand.cxx
@@ -63,7 +63,7 @@ bool cmSiteNameCommand
{
std::string host;
cmSystemTools::RunSingleCommand(hostname_cmd.c_str(),
- &host, 0, 0, cmSystemTools::OUTPUT_NONE);
+ &host, 0, 0, 0, cmSystemTools::OUTPUT_NONE);
// got the hostname
if (!host.empty())
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 95d05a6..0e0532d 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -659,7 +659,8 @@ std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
- std::string* output ,
+ std::string* captureStdOut,
+ std::string* captureStdErr,
int* retVal , const char* dir ,
OutputOption outputflag ,
double timeout )
@@ -671,9 +672,13 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
argv.push_back(a->c_str());
}
argv.push_back(0);
- if ( output )
+ if ( captureStdOut )
{
- *output = "";
+ *captureStdOut = "";
+ }
+ if (captureStdErr && captureStdErr != captureStdOut)
+ {
+ *captureStdErr = "";
}
cmsysProcess* cp = cmsysProcess_New();
@@ -693,15 +698,17 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
cmsysProcess_SetTimeout(cp, timeout);
cmsysProcess_Execute(cp);
- std::vector<char> tempOutput;
+ std::vector<char> tempStdOut;
+ std::vector<char> tempStdErr;
char* data;
int length;
int pipe;
- if(outputflag != OUTPUT_PASSTHROUGH && (output || outputflag != OUTPUT_NONE))
+ if(outputflag != OUTPUT_PASSTHROUGH &&
+ (captureStdOut || captureStdErr || outputflag != OUTPUT_NONE))
{
while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
{
- if(output || outputflag != OUTPUT_NONE)
+ if(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)
{
// Translate NULL characters in the output into valid text.
// Visual Studio 7 puts these characters in the output of its
@@ -714,9 +721,21 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
}
}
}
- if ( output )
+ if(pipe == cmsysProcess_Pipe_STDOUT ||
+ (pipe == cmsysProcess_Pipe_STDERR &&
+ captureStdOut == captureStdErr))
+ {
+ if (captureStdOut)
+ {
+ tempStdOut.insert(tempStdOut.end(), data, data+length);
+ }
+ }
+ else if(pipe == cmsysProcess_Pipe_STDERR)
{
- tempOutput.insert(tempOutput.end(), data, data+length);
+ if (captureStdErr)
+ {
+ tempStdErr.insert(tempStdErr.end(), data, data+length);
+ }
}
if(outputflag != OUTPUT_NONE)
{
@@ -740,9 +759,14 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
}
cmsysProcess_WaitForExit(cp, 0);
- if ( output && tempOutput.begin() != tempOutput.end())
+ if ( captureStdOut && tempStdOut.begin() != tempStdOut.end())
+ {
+ captureStdOut->append(&*tempStdOut.begin(), tempStdOut.size());
+ }
+ if ( captureStdErr && captureStdErr != captureStdOut &&
+ tempStdErr.begin() != tempStdErr.end())
{
- output->append(&*tempOutput.begin(), tempOutput.size());
+ captureStdErr->append(&*tempStdErr.begin(), tempStdErr.size());
}
bool result = true;
@@ -767,9 +791,9 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
std::cerr << exception_str << std::endl;
}
- if ( output )
+ if ( captureStdErr )
{
- output->append(exception_str, strlen(exception_str));
+ captureStdErr->append(exception_str, strlen(exception_str));
}
result = false;
}
@@ -780,9 +804,9 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
std::cerr << error_str << std::endl;
}
- if ( output )
+ if ( captureStdErr )
{
- output->append(error_str, strlen(error_str));
+ captureStdErr->append(error_str, strlen(error_str));
}
result = false;
}
@@ -793,9 +817,9 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
std::cerr << error_str << std::endl;
}
- if ( output )
+ if ( captureStdErr )
{
- output->append(error_str, strlen(error_str));
+ captureStdErr->append(error_str, strlen(error_str));
}
result = false;
}
@@ -806,7 +830,8 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
bool cmSystemTools::RunSingleCommand(
const char* command,
- std::string* output,
+ std::string* captureStdOut,
+ std::string* captureStdErr,
int *retVal,
const char* dir,
OutputOption outputflag,
@@ -823,8 +848,8 @@ bool cmSystemTools::RunSingleCommand(
{
return false;
}
- return cmSystemTools::RunSingleCommand(args, output,retVal,
- dir, outputflag, timeout);
+ return cmSystemTools::RunSingleCommand(args, captureStdOut, captureStdErr,
+ retVal, dir, outputflag, timeout);
}
std::string
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 433ef46..6feb6c5 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -223,7 +223,9 @@ public:
OUTPUT_NORMAL,
OUTPUT_PASSTHROUGH
};
- static bool RunSingleCommand(const char* command, std::string* output = 0,
+ static bool RunSingleCommand(const char* command,
+ std::string* captureStdOut = 0,
+ std::string* captureStdErr = 0,
int* retVal = 0, const char* dir = 0,
OutputOption outputflag = OUTPUT_MERGE,
double timeout = 0.0);
@@ -233,7 +235,8 @@ public:
* be in comand[1]...command[command.size()]
*/
static bool RunSingleCommand(std::vector<std::string> const& command,
- std::string* output = 0,
+ std::string* captureStdOut = 0,
+ std::string* captureStdErr = 0,
int* retVal = 0, const char* dir = 0,
OutputOption outputflag = OUTPUT_MERGE,
double timeout = 0.0);
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx
index c9e7a46..3cd92cb 100644
--- a/Source/cmTryRunCommand.cxx
+++ b/Source/cmTryRunCommand.cxx
@@ -224,7 +224,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs,
}
int timeout = 0;
bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(),
- out, &retVal,
+ out, out, &retVal,
0, cmSystemTools::OUTPUT_NONE, timeout);
// set the run var
char retChar[1000];
diff --git a/Source/cmcldeps.cxx b/Source/cmcldeps.cxx
index 55fc633..f3c6059 100644
--- a/Source/cmcldeps.cxx
+++ b/Source/cmcldeps.cxx
@@ -206,8 +206,9 @@ static int process( const std::string& srcfilename,
}
// run the command
int exit_code = 0;
- bool run = cmSystemTools::RunSingleCommand(command, &output, &exit_code,
- dir.c_str(), cmSystemTools::OUTPUT_NONE);
+ bool run = cmSystemTools::RunSingleCommand(command, &output, &output,
+ &exit_code, dir.c_str(),
+ cmSystemTools::OUTPUT_NONE);
// process the include directives and output everything else
std::stringstream ss(output);
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 2ef04ef..5e56957 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -267,7 +267,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::vector<std::string> cmd(ai, ae);
int retval;
if(cmSystemTools::RunSingleCommand(
- cmd, 0, &retval, NULL, cmSystemTools::OUTPUT_PASSTHROUGH))
+ cmd, 0, 0, &retval, NULL, cmSystemTools::OUTPUT_PASSTHROUGH))
{
return retval;
}
@@ -398,7 +398,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
time(&time_start);
clock_start = clock();
int ret =0;
- cmSystemTools::RunSingleCommand(command.c_str(), 0, &ret);
+ cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &ret);
clock_finish = clock();
time(&time_finish);
@@ -454,7 +454,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::string command = cmWrap('"', cmRange(args).advance(3), '"', " ");
int retval = 0;
int timeout = 0;
- if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
+ if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &retval,
directory.c_str(), cmSystemTools::OUTPUT_NORMAL, timeout) )
{
return retval;
@@ -1350,7 +1350,7 @@ bool cmcmd::RunCommand(const char* comment,
int retCode =0;
// use rc command to create .res file
cmSystemTools::RunSingleCommand(command,
- &output,
+ &output, &output,
&retCode, 0, cmSystemTools::OUTPUT_NONE);
// always print the output of the command, unless
// it is the dumb rc command banner, but if the command