From 356c26ebdfa053f59b2932c78ae81cba3c872dc3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Apr 2015 15:36:57 -0400 Subject: [PATCH] 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. --- Source/CPack/IFW/cmCPackIFWGenerator.cxx | 6 +- Source/CPack/WiX/cmCPackWIXGenerator.cxx | 3 +- Source/CPack/cmCPackDebGenerator.cxx | 6 +- Source/CPack/cmCPackDragNDropGenerator.cxx | 2 +- Source/CPack/cmCPackGenerator.cxx | 5 +- Source/CPack/cmCPackNSISGenerator.cxx | 12 ++-- Source/CPack/cmCPackOSXX11Generator.cxx | 6 +- Source/CPack/cmCPackPackageMakerGenerator.cxx | 11 ++-- Source/CTest/cmCTestScriptHandler.cxx | 12 ++-- Source/CTest/cmCTestTestHandler.cxx | 2 +- Source/cmBuildNameCommand.cxx | 2 +- Source/cmExtraEclipseCDT4Generator.cxx | 2 +- Source/cmGlobalGenerator.cxx | 4 +- Source/cmGlobalNinjaGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 4 +- Source/cmQtAutoGenerators.cxx | 11 ++-- Source/cmSiteNameCommand.cxx | 2 +- Source/cmSystemTools.cxx | 63 +++++++++++++------ Source/cmSystemTools.h | 7 ++- Source/cmTryRunCommand.cxx | 2 +- Source/cmcldeps.cxx | 5 +- Source/cmcmd.cxx | 8 +-- Tests/CMakeLib/run_compile_commands.cxx | 2 +- 23 files changed, 110 insertions(+), 69 deletions(-) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 7f06e2d8a..0439ff642 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 99eabf20f..b3eb7b2fc 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 fcf41229d..fa02a3b75 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 5da923423..4c400d9ca 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 2b18c4158..e254e9a84 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 fe6cc956b..2de2bc4a6 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 313e08b30..d533af87a 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 dfe35c9a5..880663f7e 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 7f9825c17..d1e7e3a62 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 d77825374..95cdf3b51 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1334,7 +1334,7 @@ int cmCTestTestHandler::ExecuteCommands(std::vector& 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 2a0657414..2733d7677 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 2aa4d935c..24043af44 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 4a9f62803..4b0ef582b 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 505914e2f..79a7914b4 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 8c373386f..04befee09 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 3d5103f72..329f9de24 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 20a61a046..e2970e505 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 95d05a65b..0e0532d33 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -659,7 +659,8 @@ std::vector cmSystemTools::ParseArguments(const char* command) bool cmSystemTools::RunSingleCommand(std::vectorconst& 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::vectorconst& 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::vectorconst& command, cmsysProcess_SetTimeout(cp, timeout); cmsysProcess_Execute(cp); - std::vector tempOutput; + std::vector tempStdOut; + std::vector 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::vectorconst& command, } } } - if ( output ) + if(pipe == cmsysProcess_Pipe_STDOUT || + (pipe == cmsysProcess_Pipe_STDERR && + captureStdOut == captureStdErr)) { - tempOutput.insert(tempOutput.end(), data, data+length); + if (captureStdOut) + { + tempStdOut.insert(tempStdOut.end(), data, data+length); + } + } + else if(pipe == cmsysProcess_Pipe_STDERR) + { + if (captureStdErr) + { + tempStdErr.insert(tempStdErr.end(), data, data+length); + } } if(outputflag != OUTPUT_NONE) { @@ -740,9 +759,14 @@ bool cmSystemTools::RunSingleCommand(std::vectorconst& command, } cmsysProcess_WaitForExit(cp, 0); - if ( output && tempOutput.begin() != tempOutput.end()) + if ( captureStdOut && tempStdOut.begin() != tempStdOut.end()) { - output->append(&*tempOutput.begin(), tempOutput.size()); + captureStdOut->append(&*tempStdOut.begin(), tempStdOut.size()); + } + if ( captureStdErr && captureStdErr != captureStdOut && + tempStdErr.begin() != tempStdErr.end()) + { + captureStdErr->append(&*tempStdErr.begin(), tempStdErr.size()); } bool result = true; @@ -767,9 +791,9 @@ bool cmSystemTools::RunSingleCommand(std::vectorconst& 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::vectorconst& 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::vectorconst& 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::vectorconst& 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 433ef46c1..6feb6c5bf 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 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 c9e7a4689..3cd92cb8e 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 55fc6338a..f3c6059b1 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 2ef04efdf..5e5695789 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -267,7 +267,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) std::vector 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& 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& 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 diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx index 279bcd587..26ab223dc 100644 --- a/Tests/CMakeLib/run_compile_commands.cxx +++ b/Tests/CMakeLib/run_compile_commands.cxx @@ -130,7 +130,7 @@ int main () std::vector command; cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command); if (!cmSystemTools::RunSingleCommand( - command, 0, 0, it->at("directory").c_str())) + command, 0, 0, 0, it->at("directory").c_str())) { std::cout << "ERROR: Failed to run command \"" << command[0] << "\"" << std::endl;