cmExecProgramCommand.cxx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmExecProgramCommand.h"
  14. #include "cmSystemTools.h"
  15. // cmExecProgramCommand
  16. bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 1 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::string arguments;
  24. bool doingargs = false;
  25. int count = 0;
  26. for(size_t i=0; i < args.size(); ++i)
  27. {
  28. if(doingargs)
  29. {
  30. arguments += args[i];
  31. arguments += " ";
  32. count++;
  33. }
  34. else if(args[i] == "ARGS")
  35. {
  36. count++;
  37. doingargs = true;
  38. }
  39. }
  40. std::string command;
  41. if(arguments.size())
  42. {
  43. command = cmSystemTools::ConvertToOutputPath(args[0].c_str());
  44. command += " ";
  45. command += arguments;
  46. }
  47. else
  48. {
  49. command = args[0];
  50. }
  51. std::string output;
  52. if(args.size() - count == 2)
  53. {
  54. cmSystemTools::MakeDirectory(args[1].c_str());
  55. cmSystemTools::RunCommand(command.c_str(), output,
  56. cmSystemTools::ConvertToOutputPath(args[1].c_str()).c_str());
  57. }
  58. else
  59. {
  60. cmSystemTools::RunCommand(command.c_str(), output);
  61. }
  62. return true;
  63. }