executor.hpp
Go to the documentation of this file.
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#pragma once
11
12#include <boost/fusion/algorithm/iteration/for_each.hpp>
14
15#include <Windows.h>
16
18{
19
20 struct executor
21 {
23 exe(0),
24 cmd_line(0),
25 proc_attrs(0),
26 thread_attrs(0),
27 inherit_handles(FALSE),
28#if (_WIN32_WINNT >= 0x0600)
29 creation_flags(EXTENDED_STARTUPINFO_PRESENT),
30#else
32#endif
33 env(0),
34 work_dir(0)
35#if (_WIN32_WINNT >= 0x0600)
36 ,
37 startup_info(startup_info_ex.StartupInfo)
38#endif
39 {
40#if (_WIN32_WINNT >= 0x0600)
41 ZeroMemory(&startup_info_ex, sizeof(STARTUPINFOEX));
42 startup_info.cb = sizeof(STARTUPINFOEX);
43#else
44 ZeroMemory(&startup_info, sizeof(STARTUPINFO));
45 startup_info.cb = sizeof(STARTUPINFO);
46#endif
47 startup_info.hStdInput = INVALID_HANDLE_VALUE;
48 startup_info.hStdOutput = INVALID_HANDLE_VALUE;
49 startup_info.hStdError = INVALID_HANDLE_VALUE;
50 }
51
53 {
55
59
60 template <class Arg>
61 void
62 operator()(Arg& arg) const
63 {
64 arg.on_CreateProcess_setup(e_);
65 }
66 };
67
69 {
71
75
76 template <class Arg>
77 void
78 operator()(Arg& arg) const
79 {
80 arg.on_CreateProcess_error(e_);
81 }
82 };
83
85 {
87
91
92 template <class Arg>
93 void
94 operator()(Arg& arg) const
95 {
96 arg.on_CreateProcess_success(e_);
97 }
98 };
99
100 template <class InitializerSequence>
101 child
102 operator()(const InitializerSequence& seq)
103 {
104 boost::fusion::for_each(seq, call_on_CreateProcess_setup(*this));
105
106 if (!::CreateProcess(exe,
107 cmd_line,
112 env,
113 work_dir,
115 &proc_info))
116 {
117 boost::fusion::for_each(seq, call_on_CreateProcess_error(*this));
118 }
119 else
120 {
121 boost::fusion::for_each(seq, call_on_CreateProcess_success(*this));
122 }
123
124 return child(proc_info);
125 }
126
127 LPCTSTR exe;
128 LPTSTR cmd_line;
129 LPSECURITY_ATTRIBUTES proc_attrs;
130 LPSECURITY_ATTRIBUTES thread_attrs;
133 LPVOID env;
134 LPCTSTR work_dir;
135#if (_WIN32_WINNT >= 0x0600)
136 STARTUPINFOEX startup_info_ex;
137 STARTUPINFO& startup_info;
138#else
139 STARTUPINFO startup_info;
140#endif
141 PROCESS_INFORMATION proc_info;
142 };
143
144} // namespace boost::process::windows
if(!yyvaluep)
Definition Grammar.cpp:645
child operator()(const InitializerSequence &seq)
Definition executor.hpp:102
LPSECURITY_ATTRIBUTES proc_attrs
Definition executor.hpp:129
LPSECURITY_ATTRIBUTES thread_attrs
Definition executor.hpp:130
PROCESS_INFORMATION proc_info
Definition executor.hpp:141