From 626be7884ad0261b0e4ca52fd58a0c8d79a86ae6 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 25 Oct 2004 13:16:05 -0400 Subject: [PATCH] FIX: go back to not trying to handle spaces in the path for run single command and comment it so that people know to call the right thing --- Source/cmSystemTools.cxx | 44 +++---------------- Source/cmSystemTools.h | 5 +++ Tests/Complex/Executable/complex.cxx | 3 +- Tests/ComplexOneConfig/Executable/complex.cxx | 3 +- .../Executable/complex.cxx | 3 +- 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b235b8c71..e2f830f06 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -427,54 +427,25 @@ bool cmSystemTools::RunSingleCommand( verbose = false; } - std::string program; // store name of program must be in scope function as it - // is put into argv list as a cont char* - std::vector args; // store the program and args program is args[0] - std::vector argv; // store args in a format so that process cmsysProcess can use it - // check to see if the command contains a double quoted string at the start - // if so, then just use parse arguments to split things up - if(command && *command == '\"') + std::vector args = cmSystemTools::ParseArguments(command); + + if(args.size() < 1) { - args = cmSystemTools::ParseArguments(command); + return false; } - else - { - std::string argsTemp; // Store the arguments to the program - cmSystemTools::SplitProgramFromArgs(command, program, argsTemp); - // if there is no program to run then return false - if(program.size() < 1) - { - // check for a bad call to SplitProgramFromArgs - if(strlen(command) >= 1) - { - cmSystemTools::Error("Error in SplitProgramFromArgs for: ", command); - } - return false; - } - argv.push_back(program.c_str()); // put program in as argv[0] - if(argsTemp.size()) - { - args = cmSystemTools::ParseArguments(argsTemp.c_str()); - } - } - // copy args into argv + + std::vector argv; for(std::vector::const_iterator a = args.begin(); a != args.end(); ++a) { argv.push_back(a->c_str()); } - // null terminate array argv.push_back(0); - // if the only argument is null then there is nothing to run and return false - if(!argv[0]) - { - return false; - } - if ( output ) { *output = ""; } + cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*argv.begin()); cmsysProcess_SetWorkingDirectory(cp, dir); @@ -565,7 +536,6 @@ bool cmSystemTools::RunSingleCommand( } cmsysProcess_Delete(cp); - return result; } bool cmSystemTools::RunCommand(const char* command, diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a064a31f6..cecd06584 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -188,6 +188,11 @@ public: * exit code will be stored. If the retVal is not specified and * the program exits with a code other than 0, then the this * function will return false. + * + * If the command has spaces in the path the caller MUST call + * cmSystemTools::ConvertToRunCommandPath on the command before passing + * it into this function or it will not work. The command must be correctly + * escaped for this to with spaces. */ static bool RunSingleCommand(const char* command, std::string* output = 0, int* retVal = 0, const char* dir = 0, bool verbose = true, double timeout = 0.0); diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx index 441a2910d..e0b1eaea7 100644 --- a/Tests/Complex/Executable/complex.cxx +++ b/Tests/Complex/Executable/complex.cxx @@ -117,7 +117,8 @@ int main() exe += "A"; exe += cmSystemTools::GetExecutableExtension(); int ret; - std::string errorMessage; + std::string errorMessage; + exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) { if(ret != 10) diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx index 441a2910d..e0b1eaea7 100644 --- a/Tests/ComplexOneConfig/Executable/complex.cxx +++ b/Tests/ComplexOneConfig/Executable/complex.cxx @@ -117,7 +117,8 @@ int main() exe += "A"; exe += cmSystemTools::GetExecutableExtension(); int ret; - std::string errorMessage; + std::string errorMessage; + exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) { if(ret != 10) diff --git a/Tests/ComplexRelativePaths/Executable/complex.cxx b/Tests/ComplexRelativePaths/Executable/complex.cxx index 441a2910d..e0b1eaea7 100644 --- a/Tests/ComplexRelativePaths/Executable/complex.cxx +++ b/Tests/ComplexRelativePaths/Executable/complex.cxx @@ -117,7 +117,8 @@ int main() exe += "A"; exe += cmSystemTools::GetExecutableExtension(); int ret; - std::string errorMessage; + std::string errorMessage; + exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) { if(ret != 10)