Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //////////////////////////////////////////////////////////////////////
  9. //
  10. // Redirector - to redirect the input / output of a console
  11. //
  12. // Developer: Jeff Lee
  13. // Dec 10, 2001
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. #if !defined(AFX_REDIR_H__4FB57DC3_29A3_11D5_BB60_006097553C52__INCLUDED_)
  17. #define AFX_REDIR_H__4FB57DC3_29A3_11D5_BB60_006097553C52__INCLUDED_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif // _MSC_VER > 1000
  21. class CRedirector
  22. {
  23. public:
  24. CRedirector();
  25. virtual ~CRedirector();
  26. protected:
  27. HANDLE m_hThread; // thread to receive the output of the child process
  28. HANDLE m_hEvtStop; // event to notify the redir thread to exit
  29. DWORD m_dwThreadId; // id of the redir thread
  30. DWORD m_dwWaitTime; // wait time to check the status of the child process
  31. HANDLE m_hStdinWrite; // write end of child's stdin pipe
  32. HANDLE m_hStdoutRead; // read end of child's stdout pipe
  33. HANDLE m_hChildProcess;
  34. BOOL LaunchChild(LPCTSTR pszCmdLine, LPCTSTR pszCurrentDirectory,
  35. HANDLE hStdOut, HANDLE hStdIn, HANDLE hStdErr);
  36. int RedirectStdout();
  37. void DestroyHandle(HANDLE& rhObject);
  38. static DWORD WINAPI OutputThread(LPVOID lpvThreadParam);
  39. protected:
  40. // overrides:
  41. virtual void WriteStdOut(LPCSTR pszOutput);
  42. virtual void WriteStdError(LPCSTR pszError);
  43. public:
  44. BOOL Open(LPCTSTR pszCmdLine, LPCTSTR pszCurrentDirectory = NULL);
  45. virtual void Close();
  46. BOOL Printf(PRINTF_FORMAT_STRING LPCTSTR pszFormat, ...);
  47. void SetWaitTime(DWORD dwWaitTime) { m_dwWaitTime = dwWaitTime; }
  48. };
  49. #endif // !defined(AFX_REDIR_H__4FB57DC3_29A3_11D5_BB60_006097553C52__INCLUDED_)