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
10 #ifndef BOOST_PROCESS_WINDOWS_INITIALIZERS_NULL_OUT_HPP
11 #define BOOST_PROCESS_WINDOWS_INITIALIZERS_NULL_OUT_HPP
12
13 #include <boost/winapi/process.hpp>
14 #include <boost/winapi/handles.hpp>
15 #include <boost/winapi/handle_info.hpp>
16 #include <boost/process/detail/handler_base.hpp>
17 #include <boost/process/detail/used_handles.hpp>
18 #include <boost/process/detail/windows/file_descriptor.hpp>
19
20 namespace boost { namespace process { namespace detail { namespace windows {
21
22 template<int p1, int p2>
23 struct null_out : public ::boost::process::detail::handler_base, ::boost::process::detail::uses_handles
24 {
25 file_descriptor sink {"NUL", file_descriptor::write}; //works because it gets destroyed AFTER launch.
26
get_used_handlesboost::process::detail::windows::null_out27 ::boost::winapi::HANDLE_ get_used_handles() const { return sink.handle(); }
28
29 template <typename WindowsExecutor>
30 void on_setup(WindowsExecutor &e) const;
31 };
32
33 template<>
34 template<typename WindowsExecutor>
on_setup(WindowsExecutor & e) const35 void null_out<1,-1>::on_setup(WindowsExecutor &e) const
36 {
37 boost::winapi::SetHandleInformation(sink.handle(),
38 boost::winapi::HANDLE_FLAG_INHERIT_,
39 boost::winapi::HANDLE_FLAG_INHERIT_);
40
41 e.startup_info.hStdOutput = sink.handle();
42 e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
43 e.inherit_handles = true;
44
45 }
46
47 template<>
48 template<typename WindowsExecutor>
on_setup(WindowsExecutor & e) const49 void null_out<2,-1>::on_setup(WindowsExecutor &e) const
50 {
51 boost::winapi::SetHandleInformation(sink.handle(),
52 boost::winapi::HANDLE_FLAG_INHERIT_,
53 boost::winapi::HANDLE_FLAG_INHERIT_);
54
55 e.startup_info.hStdError = sink.handle();
56 e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
57 e.inherit_handles = true;
58
59 }
60
61 template<>
62 template<typename WindowsExecutor>
on_setup(WindowsExecutor & e) const63 void null_out<1,2>::on_setup(WindowsExecutor &e) const
64 {
65 boost::winapi::SetHandleInformation(sink.handle(),
66 boost::winapi::HANDLE_FLAG_INHERIT_,
67 boost::winapi::HANDLE_FLAG_INHERIT_);
68
69 e.startup_info.hStdOutput = sink.handle();
70 e.startup_info.hStdError = sink.handle();
71 e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESTDHANDLES_;
72 e.inherit_handles = true;
73
74 }
75
76 }}}}
77
78 #endif
79