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