FIX: fix RunSingleCommand to work with spaces in the path, and with an already quoted command

This commit is contained in:
Bill Hoffman 2004-10-25 11:59:50 -04:00
parent a3ce1fb293
commit 7ed631311c
3 changed files with 46 additions and 10 deletions

View File

@ -427,26 +427,54 @@ bool cmSystemTools::RunSingleCommand(
verbose = false; verbose = false;
} }
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command); std::string program; // store name of program must be in scope function as it
// is put into argv list as a cont char*
if(args.size() < 1) std::vector<cmStdString> args; // store the program and args program is args[0]
std::vector<const char*> 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 == '\"')
{ {
return false; args = cmSystemTools::ParseArguments(command);
} }
else
std::vector<const char*> argv; {
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
for(std::vector<cmStdString>::const_iterator a = args.begin(); for(std::vector<cmStdString>::const_iterator a = args.begin();
a != args.end(); ++a) a != args.end(); ++a)
{ {
argv.push_back(a->c_str()); argv.push_back(a->c_str());
} }
// null terminate array
argv.push_back(0); 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 ) if ( output )
{ {
*output = ""; *output = "";
} }
cmsysProcess* cp = cmsysProcess_New(); cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin()); cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_SetWorkingDirectory(cp, dir); cmsysProcess_SetWorkingDirectory(cp, dir);

View File

@ -17,7 +17,11 @@ int main ()
printf("Should have ADDED_DEFINITION defined\n"); printf("Should have ADDED_DEFINITION defined\n");
return 1; return 1;
#endif #endif
if(SIZEOF_CHAR != 1)
{
printf("Size of char is not one, something is broken\n");
}
#ifdef CMAKE_IS_FUN #ifdef CMAKE_IS_FUN
return SIZEOF_CHAR-1; return SIZEOF_CHAR-1;
#else #else

View File

@ -17,7 +17,11 @@ int main ()
printf("Should have ADDED_DEFINITION defined\n"); printf("Should have ADDED_DEFINITION defined\n");
return 1; return 1;
#endif #endif
if(SIZEOF_CHAR != 1)
{
printf("Size of char is not one, something is broken\n");
}
#ifdef CMAKE_IS_FUN #ifdef CMAKE_IS_FUN
return SIZEOF_CHAR-1; return SIZEOF_CHAR-1;
#else #else