cmWin32ProcessExecution.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef cmWin32ProcessExecution_h
  14. #define cmWin32ProcessExecution_h
  15. /*
  16. * Portable 'popen' replacement for Win32.
  17. *
  18. * Written by Bill Tutt <[email protected]>. Minor tweaks
  19. * and 2.0 integration by Fredrik Lundh <[email protected]>
  20. * Return code handling by David Bolen <[email protected]>.
  21. */
  22. #include "cmStandardIncludes.h"
  23. #include "windows.h"
  24. class cmMakefile;
  25. /** \class cmWin32ProcessExecution
  26. * \brief A process executor for windows
  27. *
  28. * cmWin32ProcessExecution is a class that provides a "clean" way of
  29. * executing processes on Windows.
  30. */
  31. class cmWin32ProcessExecution
  32. {
  33. public:
  34. cmWin32ProcessExecution()
  35. {
  36. this->SetConsoleSpawn("w9xpopen.exe");
  37. this->Initialize();
  38. }
  39. void Initialize()
  40. {
  41. this->m_ProcessHandle = 0;
  42. this->m_ExitValue = -1;
  43. this->m_StdIn = 0;
  44. this->m_StdOut = 0;
  45. this->m_StdErr = 0;
  46. }
  47. bool StartProcess(const char*, const char* path, bool verbose);
  48. bool Wait(int timeout);
  49. const std::string GetOutput() const { return this->m_Output; }
  50. int GetExitValue() const { return this->m_ExitValue; }
  51. void SetConsoleSpawn(const char* prog) { this->m_ConsoleSpawn = prog; }
  52. static int Windows9xHack(const char* command);
  53. private:
  54. bool PrivateOpen(const char*, const char*, int, int);
  55. bool PrivateClose(int timeout);
  56. HANDLE m_ProcessHandle;
  57. FILE* m_StdIn;
  58. FILE* m_StdOut;
  59. FILE* m_StdErr;
  60. int m_pStdIn;
  61. int m_pStdOut;
  62. int m_pStdErr;
  63. int m_ExitValue;
  64. std::string m_Output;
  65. std::string m_ConsoleSpawn;
  66. bool m_Verbose;
  67. };
  68. #endif