Imported Upstream version 1.72.0
[platform/upstream/boost.git] / doc / html / boost / process / std_in.html
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=US-ASCII">
5 <title>Global std_in</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/reference.html#header.boost.process.io_hpp" title="Header &lt;boost/process/io.hpp&gt;">
10 <link rel="prev" href="null.html" title="Global null">
11 <link rel="next" href="std_out.html" title="Global std_out">
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="null.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.io_hpp"><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="std_out.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
25 </div>
26 <div class="refentry">
27 <a name="boost.process.std_in"></a><div class="titlepage"></div>
28 <div class="refnamediv">
29 <h2><span class="refentrytitle">Global std_in</span></h2>
30 <p>boost::process::std_in</p>
31 </div>
32 <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
33 <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../process/reference.html#header.boost.process.io_hpp" title="Header &lt;boost/process/io.hpp&gt;">boost/process/io.hpp</a>&gt;
34
35 </span><span class="emphasis"><em><span class="identifier">unspecified</span></em></span> std_in<span class="special">;</span></pre></div>
36 <div class="refsect1">
37 <a name="id-1.3.31.9.16.18.4"></a><h2>Description</h2>
38 <p>This property allows to set the input stream for the child process.</p>
39 <div class="sect1">
40 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
41 <a name="namespaceboost_1_1process_1stdin_details"></a>Details</h2></div></div></div>
42 <div class="toc"><dl class="toc">
43 <dt><span class="sect2"><a href="std_in.html#namespaceboost_1_1process_1stdin_file">File Input</a></span></dt>
44 <dt><span class="sect2"><a href="std_in.html#namespaceboost_1_1process_1stdin_pipe">Pipe Input</a></span></dt>
45 <dt><span class="sect2"><a href="std_in.html#namespaceboost_1_1process_1stdin_async_pipe">Asynchronous Pipe Input</a></span></dt>
46 <dt><span class="sect2"><a href="std_in.html#namespaceboost_1_1process_1stdin_close">Close</a></span></dt>
47 <dt><span class="sect2"><a href="std_in.html#namespaceboost_1_1process_1stdin_null">Null</a></span></dt>
48 </dl></div>
49 <div class="sect2">
50 <div class="titlepage"><div><div><h3 class="title">
51 <a name="namespaceboost_1_1process_1stdin_file"></a>File Input</h3></div></div></div>
52 <p>The file I/O simple redirects the stream to a file, for which the possible types are</p>
53 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
54 <li class="listitem"><p><code class="computeroutput">boost::filesystem::path</code></p></li>
55 <li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
56 <li class="listitem"><p><code class="computeroutput">const char_type*</code></p></li>
57 <li class="listitem"><p><code class="computeroutput">FILE*</code></p></li>
58 </ul></div>
59 <p>
60 </p>
61 <p>with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code>.</p>
62 <p>FILE* is explicitly added, so the process can easily redirect the output stream of the child to another output stream of the process. That is:</p>
63 <pre class="programlisting"><span class="identifier">system</span><span class="special">(</span><span class="string">"ls"</span><span class="special">,</span> <span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">stdin</span><span class="special">)</span><span class="special">;</span>
64 </pre>
65 <div class="warning"><table border="0" summary="Warning">
66 <tr>
67 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../doc/src/images/warning.png"></td>
68 <th align="left">Warning</th>
69 </tr>
70 <tr><td align="left" valign="top"><p>If the launching and the child process use the input, this leads to undefined behaviour.</p></td></tr>
71 </table></div>
72 <p>
73 A syntax like <code class="computeroutput">system("ls", std_out &gt; std::cerr)</code> is not possible, due to the C++ implementation not providing access to the handle.</p>
74 <p>The valid expressions for this property are</p>
75 <pre class="programlisting"><span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">file</span><span class="special">;</span>
76 <span class="identifier">std_in</span> <span class="special">=</span> <span class="identifier">file</span><span class="special">;</span>
77 </pre>
78 </div>
79 <div class="sect2">
80 <div class="titlepage"><div><div><h3 class="title">
81 <a name="namespaceboost_1_1process_1stdin_pipe"></a>Pipe Input</h3></div></div></div>
82 <p>As explained in the corresponding section, the boost.process library provides a <a class="link" href="async_pipe.html" title="Class async_pipe">async_pipe</a> class which can be used to communicate with child processes.</p>
83 <div class="note"><table border="0" summary="Note">
84 <tr>
85 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
86 <th align="left">Note</th>
87 </tr>
88 <tr><td align="left" valign="top"><p>Technically the <a class="link" href="async_pipe.html" title="Class async_pipe">async_pipe</a> works synchronous here, since no asio implementation is used by the library here. The async-operation will then however not end if the process is finished, since the pipe remains open. You can use the async_close function with on_exit to fix that.</p></td></tr>
89 </table></div>
90 <p>
91 Valid expressions with pipes are these:</p>
92 <pre class="programlisting"><span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">pipe</span><span class="special">;</span>
93 <span class="identifier">std_in</span> <span class="special">=</span> <span class="identifier">pipe</span><span class="special">;</span>
94 </pre>
95 <p>Where the valid types for <code class="computeroutput">pipe</code> are the following:</p>
96 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
97 <li class="listitem"><p><code class="computeroutput"><a class="link" href="basic_pipe.html" title="Class template basic_pipe">basic_pipe</a></code></p></li>
98 <li class="listitem"><p><code class="computeroutput"><a class="link" href="async_pipe.html" title="Class async_pipe">async_pipe</a></code></p></li>
99 <li class="listitem"><p><code class="computeroutput"><a class="link" href="basic_opstream.html" title="Class template basic_opstream">basic_opstream</a></code></p></li>
100 <li class="listitem"><p><code class="computeroutput"><a class="link" href="basic_pstream.html" title="Class template basic_pstream">basic_pstream</a></code></p></li>
101 </ul></div>
102 <p>
103 </p>
104 <p>Note that the pipe may also be used between several processes, like this:</p>
105 <pre class="programlisting"><span class="identifier">pipe</span> <span class="identifier">p</span><span class="special">;</span>
106 <span class="identifier">child</span> <span class="identifier">c1</span><span class="special">(</span><span class="string">"nm"</span><span class="special">,</span> <span class="string">"a.out"</span><span class="special">,</span> <span class="identifier">std_out</span><span class="special">&gt;</span><span class="identifier">p</span><span class="special">)</span><span class="special">;</span>
107 <span class="identifier">child</span> <span class="identifier">c2</span><span class="special">(</span><span class="string">"c++filt"</span><span class="special">,</span> <span class="identifier">std_in</span><span class="special">&lt;</span><span class="identifier">p</span><span class="special">)</span><span class="special">;</span>
108 </pre>
109 </div>
110 <div class="sect2">
111 <div class="titlepage"><div><div><h3 class="title">
112 <a name="namespaceboost_1_1process_1stdin_async_pipe"></a>Asynchronous Pipe Input</h3></div></div></div>
113 <p>Asynchronous Pipe I/O classifies communication which has automatically handling of the asynchronous operations by the process library. This means, that a pipe will be constructed, the async_read/-write will be automatically started, and that the end of the child process will also close the pipe.</p>
114 <p>Valid types for pipe I/O are the following:</p>
115 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
116 <li class="listitem"><p><code class="computeroutput">boost::asio::const_buffer</code> <a href="#ftn.id-1.3.31.9.16.18.4.3.4.4.1.1.1.2" class="footnote" name="id-1.3.31.9.16.18.4.3.4.4.1.1.1.2"><sup class="footnote">[30]</sup></a> </p></li>
117 <li class="listitem"><p><code class="computeroutput">boost::asio::mutable_buffer</code> <a href="#ftn.id-1.3.31.9.16.18.4.3.4.4.1.2.1.2" class="footnote" name="id-1.3.31.9.16.18.4.3.4.4.1.2.1.2"><sup class="footnote">[31]</sup></a> </p></li>
118 <li class="listitem"><p><code class="computeroutput">boost::asio::streambuf</code></p></li>
119 </ul></div>
120 <p>
121 </p>
122 <p>Valid expressions with pipes are these:</p>
123 <pre class="programlisting"><span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">buffer</span><span class="special">;</span>
124 <span class="identifier">std_in</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span>
125 <span class="identifier">std_out</span> <span class="special">&gt;</span> <span class="identifier">buffer</span><span class="special">;</span>
126 <span class="identifier">std_out</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span>
127 <span class="identifier">std_err</span> <span class="special">&gt;</span> <span class="identifier">buffer</span><span class="special">;</span>
128 <span class="identifier">std_err</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span>
129 <span class="special">(</span><span class="identifier">std_out</span> <span class="special">&amp;</span> <span class="identifier">std_err</span><span class="special">)</span> <span class="special">&gt;</span> <span class="identifier">buffer</span><span class="special">;</span>
130 <span class="special">(</span><span class="identifier">std_out</span> <span class="special">&amp;</span> <span class="identifier">std_err</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">buffer</span><span class="special">;</span>
131 </pre>
132 <div class="note"><table border="0" summary="Note">
133 <tr>
134 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
135 <th align="left">Note</th>
136 </tr>
137 <tr><td align="left" valign="top">
138 <p>It is also possible to get a future for std_in, by chaining another <code class="computeroutput">std::future&lt;void&gt;</code> onto it, so you can wait for the input to be completed. It looks like this: </p>
139 <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">future</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">fut</span><span class="special">;</span>
140 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">io_context</span> <span class="identifier">ios</span><span class="special">;</span>
141 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">data</span><span class="special">;</span>
142 <span class="identifier">child</span> <span class="identifier">c</span><span class="special">(</span><span class="string">"prog"</span><span class="special">,</span> <span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">buffer</span><span class="special">(</span><span class="identifier">data</span><span class="special">)</span> <span class="special">&gt;</span>  <span class="identifier">fut</span><span class="special">,</span> <span class="identifier">ios</span><span class="special">)</span><span class="special">;</span>
143 <span class="identifier">fut</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
144 </pre>
145 </td></tr>
146 </table></div>
147 <p>
148 </p>
149 <div class="note"><table border="0" summary="Note">
150 <tr>
151 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
152 <th align="left">Note</th>
153 </tr>
154 <tr><td align="left" valign="top"><p><code class="computeroutput">boost::asio::buffer</code> is also available in the <code class="computeroutput">boost::process</code> namespace.</p></td></tr>
155 </table></div>
156 <p>
157 </p>
158 <div class="warning"><table border="0" summary="Warning">
159 <tr>
160 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../doc/src/images/warning.png"></td>
161 <th align="left">Warning</th>
162 </tr>
163 <tr><td align="left" valign="top"><p>This feature requires <code class="computeroutput">boost/process/async.hpp</code> to be included and a reference to <code class="computeroutput">boost::asio::io_context</code> to be passed to the launching function.</p></td></tr>
164 </table></div>
165 <p>
166 </p>
167 </div>
168 <div class="sect2">
169 <div class="titlepage"><div><div><h3 class="title">
170 <a name="namespaceboost_1_1process_1stdin_close"></a>Close</h3></div></div></div>
171 <p>The input stream can be closed, so it cannot be read from. This will lead to an error when attempted.</p>
172 <p>This can be achieved by the following syntax.</p>
173 <pre class="programlisting"><span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">close</span><span class="special">;</span>
174 <span class="identifier">std_in</span> <span class="special">=</span> <span class="identifier">close</span><span class="special">;</span>
175 <span class="identifier">std_in</span><span class="special">.</span><span class="identifier">close</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
176 </pre>
177 </div>
178 <div class="sect2">
179 <div class="titlepage"><div><div><h3 class="title">
180 <a name="namespaceboost_1_1process_1stdin_null"></a>Null</h3></div></div></div>
181 <p>The input stream can be redirected to read from the null-device, which means that only <code class="computeroutput">EOF</code> is read.</p>
182 <p>The syntax to achieve that has the following variants:</p>
183 <pre class="programlisting"><span class="identifier">std_in</span> <span class="special">&lt;</span> <span class="identifier">null</span><span class="special">;</span>
184 <span class="identifier">std_in</span> <span class="special">=</span> <span class="identifier">null</span><span class="special">;</span>
185 <span class="identifier">std_in</span><span class="special">.</span><span class="identifier">null</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
186 </pre>
187 <p> </p>
188 </div>
189 </div>
190 </div>
191 <div class="footnotes">
192 <br><hr style="width:100; text-align:left;margin-left: 0">
193 <div id="ftn.id-1.3.31.9.16.18.4.3.4.4.1.1.1.2" class="footnote"><p><a href="#id-1.3.31.9.16.18.4.3.4.4.1.1.1.2" class="para"><sup class="para">[30] </sup></a> Constructed with <code class="computeroutput">boost::asio::buffer</code></p></div>
194 <div id="ftn.id-1.3.31.9.16.18.4.3.4.4.1.2.1.2" class="footnote"><p><a href="#id-1.3.31.9.16.18.4.3.4.4.1.2.1.2" class="para"><sup class="para">[31] </sup></a> Constructed with <code class="computeroutput">boost::asio::buffer</code></p></div>
195 </div>
196 </div>
197 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
198 <td align="left"></td>
199 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2012 Julio M. Merino Vidal, Ilya Sokolov,
200       Felipe Tanus, Jeff Flinn, Boris Schaeling<br>Copyright &#169; 2016 Klemens D. Morgenstern<p>
201         Distributed under the Boost Software License, Version 1.0. (See accompanying
202         file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
203       </p>
204 </div></td>
205 </tr></table>
206 <hr>
207 <div class="spirit-nav">
208 <a accesskey="p" href="null.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.io_hpp"><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="std_out.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
209 </div>
210 </body>
211 </html>