cmProcess.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 false if process has exited, true otherwise
  35. bool CheckOutput(double timeout);
  36. // return the process status
  37. int GetProcessStatus();
  38. // return true if the process is running
  39. bool IsRunning();
  40. // Report the status of the program
  41. int ReportStatus();
  42. int GetId() { return this->Id; }
  43. void SetId(int id) { this->Id = id;}
  44. int GetExitValue() { return this->ExitValue;}
  45. double GetTotalTime() { return this->TotalTime;}
  46. int GetNextOutputLine(std::string& stdOutLine, std::string& stdErrLine,
  47. bool& gotStdOut, bool& gotStdErr, bool running);
  48. private:
  49. int LastOutputPipe;
  50. double Timeout;
  51. double StartTime;
  52. double TotalTime;
  53. cmsysProcess* Process;
  54. std::vector<char> StdErrorBuffer;
  55. std::vector<char> StdOutBuffer;
  56. std::string Command;
  57. std::string WorkingDirectory;
  58. std::vector<std::string> Arguments;
  59. std::vector<const char*> ProcessArgs;
  60. std::string Output;
  61. int Id;
  62. int ExitValue;
  63. };
  64. #endif