null_out.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2006, 2007 Julio M. Merino Vidal
  2. // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
  3. // Copyright (c) 2009 Boris Schaeling
  4. // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
  5. // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_PROCESS_WINDOWS_INITIALIZERS_NULL_OUT_HPP
  10. #define BOOST_PROCESS_WINDOWS_INITIALIZERS_NULL_OUT_HPP
  11. #include <boost/winapi/process.hpp>
  12. #include <boost/winapi/handles.hpp>
  13. #include <boost/winapi/handle_info.hpp>
  14. #include <boost/process/detail/handler_base.hpp>
  15. #include <boost/process/detail/windows/file_descriptor.hpp>
  16. namespace boost { namespace process { namespace detail { namespace windows {
  17. template<int p1, int p2>
  18. struct null_out : public ::boost::process::detail::handler_base
  19. {
  20. file_descriptor sink {"NUL", file_descriptor::write}; //works because it gets destroyed AFTER launch.
  21. template <typename WindowsExecutor>
  22. void on_setup(WindowsExecutor &e) const;
  23. };
  24. template<>
  25. template<typename WindowsExecutor>
  26. void null_out<1,-1>::on_setup(WindowsExecutor &e) const
  27. {
  28. boost::winapi::SetHandleInformation(sink.handle(),
  29. boost::winapi::HANDLE_FLAG_INHERIT_,
  30. boost::winapi::HANDLE_FLAG_INHERIT_);
  31. e.startup_info.hStdOutput = sink.handle();
  32. e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
  33. e.inherit_handles = true;
  34. }
  35. template<>
  36. template<typename WindowsExecutor>
  37. void null_out<2,-1>::on_setup(WindowsExecutor &e) const
  38. {
  39. boost::winapi::SetHandleInformation(sink.handle(),
  40. boost::winapi::HANDLE_FLAG_INHERIT_,
  41. boost::winapi::HANDLE_FLAG_INHERIT_);
  42. e.startup_info.hStdError = sink.handle();
  43. e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
  44. e.inherit_handles = true;
  45. }
  46. template<>
  47. template<typename WindowsExecutor>
  48. void null_out<1,2>::on_setup(WindowsExecutor &e) const
  49. {
  50. boost::winapi::SetHandleInformation(sink.handle(),
  51. boost::winapi::HANDLE_FLAG_INHERIT_,
  52. boost::winapi::HANDLE_FLAG_INHERIT_);
  53. e.startup_info.hStdOutput = sink.handle();
  54. e.startup_info.hStdError = sink.handle();
  55. e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
  56. e.inherit_handles = true;
  57. }
  58. }}}}
  59. #endif