cmProcess.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. #ifndef cmProcess_h
  14. #define cmProcess_h
  15. #include "cmStandardIncludes.h"
  16. #include <cmsys/Process.h>
  17. /** \class cmProcess
  18. * \brief run a process with c++
  19. *
  20. * cmProcess wraps the kwsys process stuff in a c++ class.
  21. */
  22. class cmProcess
  23. {
  24. public:
  25. cmProcess();
  26. ~cmProcess();
  27. const char* GetCommand() { return this->Command.c_str();}
  28. void SetCommand(const char* command);
  29. void SetCommandArguments(std::vector<std::string> const& arg);
  30. void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir;}
  31. void SetTimeout(double t) { this->Timeout = t;}
  32. // Return true if the process starts
  33. bool StartProcess();
  34. // return process state
  35. int CheckOutput(double timeout,
  36. std::string& stdOutLine,
  37. std::string& stdErrLine);
  38. // return the process status
  39. int GetProcessStatus();
  40. // return true if the process is running
  41. bool IsRunning();
  42. // Report the status of the program
  43. int ReportStatus();
  44. int GetId() { return this->Id; }
  45. void SetId(int id) { this->Id = id;}
  46. int GetExitValue() { return this->ExitValue;}
  47. private:
  48. int LastOutputPipe;
  49. double Timeout;
  50. double StartTime;
  51. double TotalTime;
  52. cmsysProcess* Process;
  53. std::vector<char> StdErrorBuffer;
  54. std::vector<char> StdOutBuffer;
  55. std::string Command;
  56. std::string WorkingDirectory;
  57. std::vector<std::string> Arguments;
  58. std::vector<const char*> ProcessArgs;
  59. std::string Output;
  60. int Id;
  61. int ExitValue;
  62. };
  63. #endif