1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Extensions</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../process.html" title="Chapter 29. Boost.Process"> 10<link rel="prev" href="design.html" title="Design Rationale"> 11<link rel="next" href="faq.html" title="Frequently Asked Questions"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="design.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../process.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="faq.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="boost_process.extend"></a><a class="link" href="extend.html" title="Extensions">Extensions</a> 29</h2></div></div></div> 30<div class="toc"><dl class="toc"> 31<dt><span class="section"><a href="extend.html#boost_process.extend.structure">Structure</a></span></dt> 32<dt><span class="section"><a href="extend.html#boost_process.extend.simple">Simple extensions</a></span></dt> 33<dt><span class="section"><a href="extend.html#boost_process.extend.handler">Handler Types</a></span></dt> 34<dt><span class="section"><a href="extend.html#boost_process.extend.async">Asynchronous Functionality</a></span></dt> 35<dt><span class="section"><a href="extend.html#boost_process.extend.error">Error handling</a></span></dt> 36<dt><span class="section"><a href="extend.html#boost_process.extend.exec_over">Executor Overloading</a></span></dt> 37</dl></div> 38<p> 39 To extend the library, the header <code class="computeroutput"><a class="link" href="../process/reference.html#header.boost.process.extend_hpp" title="Header <boost/process/extend.hpp>">extend</a></code> 40 is provided. 41 </p> 42<p> 43 It only provides the explicit style for custom properties, but no implicit 44 style. 45 </p> 46<p> 47 What this means is, that a custom initializer can be implemented, a reference 48 which can be passed to one of the launching functions. If a class inherits 49 <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">boost::process::extend::handler</a></code> 50 it will be regarded as an initializer and thus directly put into the sequence 51 the executor gets passed. 52 </p> 53<div class="section"> 54<div class="titlepage"><div><div><h3 class="title"> 55<a name="boost_process.extend.structure"></a><a class="link" href="extend.html#boost_process.extend.structure" title="Structure">Structure</a> 56</h3></div></div></div> 57<p> 58 The executor calls different handlers of the initializers during the process 59 launch. The basic structure consists of three functions, as given below: 60 </p> 61<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 62<li class="listitem"> 63 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_setup.html" title="Global on_setup">on_setup</a></code> 64 </li> 65<li class="listitem"> 66 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_error.html" title="Global on_error">on_error</a></code> 67 </li> 68<li class="listitem"> 69 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">on_success</a></code> 70 </li> 71</ul></div> 72<p> 73 <img src="windows_exec.svg"> 74 </p> 75<p> 76 Additionally posix provides three more handlers, listed below: 77 </p> 78<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 79<li class="listitem"> 80 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_fork_error.html" title="Global on_fork_error">on_fork_error</a></code> 81 </li> 82<li class="listitem"> 83 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_exec_setup.html" title="Global on_exec_setup">on_exec_setup</a></code> 84 </li> 85<li class="listitem"> 86 <code class="computeroutput"><a class="link" href="../boost/process/extend/on_exec_error.html" title="Global on_exec_error">on_exec_error</a></code> 87 </li> 88</ul></div> 89<p> 90 For more information see the reference of <code class="computeroutput"><a class="link" href="../boost/process/extend/posix_executor.html" title="Struct template posix_executor">posix_executor</a></code>. 91 </p> 92</div> 93<div class="section"> 94<div class="titlepage"><div><div><h3 class="title"> 95<a name="boost_process.extend.simple"></a><a class="link" href="extend.html#boost_process.extend.simple" title="Simple extensions">Simple extensions</a> 96</h3></div></div></div> 97<p> 98 The simplest extension just takes a single handler, which can be done in 99 a functional style. So let's start with a simple hello-world example, while 100 we use a C++14 generic lambda. 101 </p> 102<p> 103</p> 104<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">process</span><span class="special">;</span> 105<span class="keyword">namespace</span> <span class="identifier">ex</span> <span class="special">=</span> <span class="identifier">bp</span><span class="special">::</span><span class="identifier">extend</span><span class="special">;</span> 106 107<code class="computeroutput"><a class="link" href="../boost/process/child.html" title="Class child">child</a></code> <span class="identifier">c</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code><span class="special">=[](</span><span class="keyword">auto</span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> <span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"hello world"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;});</span> 108</pre> 109<p> 110 </p> 111<p> 112 Considering that lambdas can also capture values, data can easily be shared 113 between handlers. 114 </p> 115<p> 116 To see which members the executor has, refer to <code class="computeroutput"><a class="link" href="../boost/process/extend/windows_executor.html" title="Struct template windows_executor">windows_executor</a></code> 117 and <code class="computeroutput"><a class="link" href="../boost/process/extend/posix_executor.html" title="Struct template posix_executor">posix_executor</a></code>. 118 </p> 119<div class="note"><table border="0" summary="Note"> 120<tr> 121<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td> 122<th align="left">Note</th> 123</tr> 124<tr><td align="left" valign="top"><p> 125 Combined with <code class="computeroutput"><a class="link" href="../boost/process/on_exit.html" title="Global on_exit">on_exit</a></code> 126 this can also handle the process exit. 127 </p></td></tr> 128</table></div> 129<div class="caution"><table border="0" summary="Caution"> 130<tr> 131<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/src/images/caution.png"></td> 132<th align="left">Caution</th> 133</tr> 134<tr><td align="left" valign="top"><p> 135 The posix handler symbols are not defined on windows. 136 </p></td></tr> 137</table></div> 138</div> 139<div class="section"> 140<div class="titlepage"><div><div><h3 class="title"> 141<a name="boost_process.extend.handler"></a><a class="link" href="extend.html#boost_process.extend.handler" title="Handler Types">Handler Types</a> 142</h3></div></div></div> 143<p> 144 Since the previous example is in a functional style, it is not very reusable. 145 To solve that problem, the <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code> 146 has an alias in the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">process</span><span class="special">::</span><span class="identifier">extend</span></code> 147 namespace, to be inherited. So let's implement the hello world example in 148 a class. 149 </p> 150<p> 151</p> 152<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">hello_world</span> <span class="special">:</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code> 153<span class="special">{</span> 154 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Executor</span><span class="special">></span> 155 <span class="keyword">void</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code><span class="special">(</span><span class="identifier">Executor</span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> <span class="keyword">const</span> 156 <span class="special">{</span> 157 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"hello world"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 158 <span class="special">}</span> 159<span class="special">};</span> 160 161<span class="comment">//in our function</span> 162<code class="computeroutput"><a class="link" href="../boost/process/child.html" title="Class child">child</a></code> <span class="identifier">c</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">hello_world</span><span class="special">());</span> 163</pre> 164<p> 165 </p> 166<div class="note"><table border="0" summary="Note"> 167<tr> 168<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td> 169<th align="left">Note</th> 170</tr> 171<tr><td align="left" valign="top"><p> 172 The implementation is done via overloading, not overriding. 173 </p></td></tr> 174</table></div> 175<p> 176 Every handler not implemented defaults to <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code>, 177 where an empty handler is defined for each event. 178 </p> 179</div> 180<div class="section"> 181<div class="titlepage"><div><div><h3 class="title"> 182<a name="boost_process.extend.async"></a><a class="link" href="extend.html#boost_process.extend.async" title="Asynchronous Functionality">Asynchronous Functionality</a> 183</h3></div></div></div> 184<p> 185 Since <code class="computeroutput"><span class="identifier">boost</span><span class="special">.</span><span class="identifier">process</span></code> provides an interface for <a href="http://www.boost.org/doc/libs/release/libs/asio/" target="_top">boost.asio</a>, 186 this functionality is also available for extensions. If the class needs the 187 <a href="http://www.boost.org/doc/libs/release/doc/html/boost_asio/reference/io_context.html" target="_top">boost::asio::io_context</a> 188 for some reason, the following code will do that. 189 </p> 190<p> 191</p> 192<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">async_foo</span> <span class="special">:</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/require_io_context.html" title="Struct require_io_context">ex::require_io_context</a></code> 193<span class="special">{</span> 194 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Executor</span><span class="special">></span> 195 <span class="keyword">void</span> <span class="identifier">on_setup</span><span class="special">(</span><span class="identifier">Executor</span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 196 <span class="special">{</span> 197 <a href="http://www.boost.org/doc/libs/release/doc/html/boost_asio/reference/io_context.html" target="_top">boost::asio::io_context</a> <span class="special">&</span> <span class="identifier">ios</span> <span class="special">=</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/get_io_context.html" title="Function template get_io_context">ex::get_io_context</a></code><span class="special">(</span><span class="identifier">exec</span><span class="special">.</span><span class="identifier">seq</span><span class="special">);</span> <span class="comment">//gives us a reference and a compiler error if not present.</span> 198 <span class="comment">//do something with ios</span> 199 <span class="special">}</span> 200<span class="special">};</span> 201</pre> 202<p> 203 </p> 204<div class="note"><table border="0" summary="Note"> 205<tr> 206<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td> 207<th align="left">Note</th> 208</tr> 209<tr><td align="left" valign="top"><p> 210 Inheriting <code class="computeroutput">require_io_context</code> 211 is necessary, so <code class="computeroutput"><a class="link" href="../boost/process/system.html" title="Function template system">system</a></code> 212 provides one. 213 </p></td></tr> 214</table></div> 215<p> 216 Additionally the handler can provide a function that is invoked when the 217 child process exits. This is done through <code class="computeroutput"><a class="link" href="../boost/process/extend/async_handler.html" title="Struct async_handler">ex::async_handler</a></code>. 218 </p> 219<div class="note"><table border="0" summary="Note"> 220<tr> 221<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td> 222<th align="left">Note</th> 223</tr> 224<tr><td align="left" valign="top"><p> 225 <code class="computeroutput">async_handler</code> 226 implies <code class="computeroutput">require_io_context</code> 227 . 228 </p></td></tr> 229</table></div> 230<p> 231</p> 232<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">async_bar</span> <span class="special">:</span> <span class="identifier">__handler</span><span class="special">,</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/async_handler.html" title="Struct async_handler">ex::async_handler</a></code> 233<span class="special">{</span> 234 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Executor</span><span class="special">></span> 235 <span class="identifier">std</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span><span class="keyword">void</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&)></span> <span class="identifier">on_exit_handler</span><span class="special">(</span><span class="identifier">Executor</span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 236 <span class="special">{</span> 237 <span class="keyword">auto</span> <span class="identifier">handler_</span> <span class="special">=</span> <span class="keyword">this</span><span class="special">-></span><span class="identifier">handler</span><span class="special">;</span> 238 <span class="keyword">return</span> <span class="special">[</span><span class="identifier">handler_</span><span class="special">](</span><span class="keyword">int</span> <span class="identifier">exit_code</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span><span class="special">)</span> 239 <span class="special">{</span> 240 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"hello world, I exited with "</span> <span class="special"><<</span> <span class="identifier">exit_code</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 241 <span class="special">};</span> 242 243 <span class="special">}</span> 244<span class="special">};</span> 245</pre> 246<p> 247 </p> 248<div class="caution"><table border="0" summary="Caution"> 249<tr> 250<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/src/images/caution.png"></td> 251<th align="left">Caution</th> 252</tr> 253<tr><td align="left" valign="top"><p> 254 <code class="computeroutput"><span class="identifier">on_exit_handler</span></code> does not 255 default and is always required when <code class="computeroutput"><a class="link" href="../boost/process/extend/async_handler.html" title="Struct async_handler">async_handler</a></code> 256 is inherited. 257 </p></td></tr> 258</table></div> 259<div class="caution"><table border="0" summary="Caution"> 260<tr> 261<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/src/images/caution.png"></td> 262<th align="left">Caution</th> 263</tr> 264<tr><td align="left" valign="top"><p> 265 <code class="computeroutput"><span class="identifier">on_exit_handler</span></code> uses <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">signal_set</span></code> to listen for SIGCHLD on posix. 266 The application must not also register a signal handler for SIGCHLD using 267 functions such as <code class="computeroutput"><span class="identifier">signal</span><span class="special">()</span></code> or <code class="computeroutput"><span class="identifier">sigaction</span><span class="special">()</span></code> (but using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">signal_set</span></code> 268 is fine). 269 </p></td></tr> 270</table></div> 271</div> 272<div class="section"> 273<div class="titlepage"><div><div><h3 class="title"> 274<a name="boost_process.extend.error"></a><a class="link" href="extend.html#boost_process.extend.error" title="Error handling">Error handling</a> 275</h3></div></div></div> 276<p> 277 If an error occurs in the initializers it shall be told to the executor and 278 not handled directly. This is because the behaviour can be changed through 279 arguments passed to the launching function. Hence the executor has the function 280 <code class="computeroutput"><span class="identifier">set_error</span></code>, which takes an 281 <a href="http://en.cppreference.com/w/cpp/error/error_code" target="_top">std::error_code</a> 282 and a string. Depending on the configuration of the executor, this may either 283 throw, set an internal <code class="computeroutput"><span class="identifier">error_code</span></code>, 284 or do nothing. 285 </p> 286<p> 287 So let's take a simple example, where we set a randomly chosen <code class="computeroutput"><span class="identifier">error_code</span></code>. 288 </p> 289<p> 290</p> 291<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">set_error</span> <span class="special">=</span> <span class="special">[](</span><span class="keyword">auto</span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 292 <span class="special">{</span> 293 <span class="identifier">std</span><span class="special">::</span><span class="identifier">error_code</span> <span class="identifier">ec</span><span class="special">{</span><span class="number">42</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">system_category</span><span class="special">()};</span> 294 <span class="identifier">exec</span><span class="special">.</span><span class="identifier">set_error</span><span class="special">(</span><span class="identifier">ec</span><span class="special">,</span> <span class="string">"a fake error"</span><span class="special">);</span> 295 296 <span class="special">};</span> 297<code class="computeroutput"><a class="link" href="../boost/process/child.html" title="Class child">child</a></code> <span class="identifier">c</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">on_setup</span><span class="special">=</span><span class="identifier">set_error</span><span class="special">);</span> 298</pre> 299<p> 300 </p> 301<p> 302 Since we do not specify the error-handling mode in this example, this will 303 throw <code class="computeroutput"><a class="link" href="../boost/process/process_error.html" title="Struct process_error">process_error</a></code>. 304 </p> 305</div> 306<div class="section"> 307<div class="titlepage"><div><div><h3 class="title"> 308<a name="boost_process.extend.exec_over"></a><a class="link" href="extend.html#boost_process.extend.exec_over" title="Executor Overloading">Executor Overloading</a> 309</h3></div></div></div> 310<p> 311 Now that we have a custom initializer, let's consider how we can handle differences 312 between different executors. The distinction is between posix and windows 313 and <code class="computeroutput"><span class="keyword">char</span></code> and <code class="computeroutput"><span class="keyword">wchar_t</span></code> 314 on windows. One solution is to use the <a href="http://www.boost.org/doc/libs/master/boost/system/api_config.hpp" target="_top">BOOST_WINDOWS_API 315 and BOOST_POSIX_API</a> macros, which are automatically available as 316 soon as any process-header is included. 317 </p> 318<p> 319 Another variant are the type aliases <code class="computeroutput"><a class="link" href="../boost/process/extend/posix_executor.html" title="Struct template posix_executor">ex::posix_executor</a></code> 320 and <code class="computeroutput"><a class="link" href="../boost/process/extend/windows_executor.html" title="Struct template windows_executor">ex::windows_executor</a></code>, 321 where the executor, not on the current system is a forward-declaration. This 322 works fine, because the function will never get invoked. So let's implement 323 another example, which prints the executable name <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code>. 324 </p> 325<p> 326</p> 327<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">hello_exe</span> <span class="special">:</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code> 328<span class="special">{</span> 329 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Sequence</span><span class="special">></span> 330 <span class="keyword">void</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code><span class="special">(</span><code class="computeroutput"><a class="link" href="../boost/process/extend/posix_executor.html" title="Struct template posix_executor">ex::posix_executor</a></code><span class="special"><</span><span class="identifier">Sequence</span><span class="special">></span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 331 <span class="special">{</span> 332 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"posix-exe: "</span> <span class="special"><<</span> <span class="identifier">exec</span><span class="special">.</span><span class="identifier">exe</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 333 <span class="special">}</span> 334 335 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Sequence</span><span class="special">></span> 336 <span class="keyword">void</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code><span class="special">(</span><code class="computeroutput"><a class="link" href="../boost/process/extend/windows_executor.html" title="Struct template windows_executor">ex::windows_executor</a></code><span class="special"><</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">Sequence</span><span class="special">></span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 337 <span class="special">{</span> 338 <span class="comment">//note: exe might be a nullptr on windows.</span> 339 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">exec</span><span class="special">.</span><span class="identifier">exe</span> <span class="special">!=</span> <span class="keyword">nullptr</span><span class="special">)</span> 340 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"windows-exe: "</span> <span class="special"><<</span> <span class="identifier">exec</span><span class="special">.</span><span class="identifier">exe</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 341 <span class="keyword">else</span> 342 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"windows didn't use exe"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 343 <span class="special">}</span> 344 345 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Sequence</span><span class="special">></span> 346 <span class="keyword">void</span> <code class="computeroutput"><a class="link" href="../boost/process/extend/on_success.html" title="Global on_success">ex::on_success</a></code><span class="special">(</span><code class="computeroutput"><a class="link" href="../boost/process/extend/windows_executor.html" title="Struct template windows_executor">ex::windows_executor</a></code><span class="special"><</span><span class="keyword">wchar_t</span><span class="special">,</span> <span class="identifier">Sequence</span><span class="special">></span> <span class="special">&</span> <span class="identifier">exec</span><span class="special">)</span> 347 <span class="special">{</span> 348 <span class="comment">//note: exe might be a nullptr on windows.</span> 349 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">exec</span><span class="special">.</span><span class="identifier">exe</span> <span class="special">!=</span> <span class="keyword">nullptr</span><span class="special">)</span> 350 <span class="identifier">std</span><span class="special">::</span><span class="identifier">wcout</span> <span class="special"><<</span> <span class="identifier">L</span><span class="string">"windows-exe: "</span> <span class="special"><<</span> <span class="identifier">exec</span><span class="special">.</span><span class="identifier">exe</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 351 <span class="keyword">else</span> 352 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"windows didn't use exe"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 353 <span class="special">}</span> 354 355<span class="special">};</span> 356</pre> 357<p> 358 </p> 359<p> 360 So given our example, the definitions with the non-native executor are still 361 a template so that they will not be evaluated if not used. Hence this provides 362 a way to implement system-specific code without using the preprocessor. 363 </p> 364<div class="note"><table border="0" summary="Note"> 365<tr> 366<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td> 367<th align="left">Note</th> 368</tr> 369<tr><td align="left" valign="top"><p> 370 If you only write a partial implementation, e.g. only for <code class="computeroutput"><a class="link" href="../boost/process/extend/posix_executor.html" title="Struct template posix_executor">ex::posix_executor</a></code>, 371 the other variants will default to <code class="computeroutput"><a class="link" href="../boost/process/extend/handler.html" title="Struct handler">handler</a></code> 372 </p></td></tr> 373</table></div> 374<p> 375 . 376 </p> 377</div> 378</div> 379<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 380<td align="left"></td> 381<td align="right"><div class="copyright-footer">Copyright © 2006-2012 Julio M. Merino Vidal, Ilya Sokolov, 382 Felipe Tanus, Jeff Flinn, Boris Schaeling<br>Copyright © 2016 Klemens D. Morgenstern<p> 383 Distributed under the Boost Software License, Version 1.0. (See accompanying 384 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 385 </p> 386</div></td> 387</tr></table> 388<hr> 389<div class="spirit-nav"> 390<a accesskey="p" href="design.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../process.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="faq.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 391</div> 392</body> 393</html> 394