summaryrefslogtreecommitdiff
path: root/doc/html/boost/process/env.html
blob: c948529676b3417b83cba8e858ccfc897234a44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Global env</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../process/reference.html#header.boost.process.env_hpp" title="Header &lt;boost/process/env.hpp&gt;">
<link rel="prev" href="cmd.html" title="Global cmd">
<link rel="next" href="basic_environment.html" title="Class template basic_environment">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmd.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.env_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="basic_environment.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.process.env"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Global env</span></h2>
<p>boost::process::env</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<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.env_hpp" title="Header &lt;boost/process/env.hpp&gt;">boost/process/env.hpp</a>&gt;

</span><span class="emphasis"><em><span class="identifier">unspecified</span></em></span> env<span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idp433083104"></a><h2>Description</h2>
<p>The <code class="computeroutput">env</code> property provides a functional way to modify the environment used by the child process. If none is passed the environment is inherited from the father process. Appending means that the environment will be interpreted as a ';' or ':' seperated list as used in <code class="computeroutput">PATH</code>.</p>
<p>On both <code class="computeroutput">posix</code> and <code class="computeroutput">windows</code> the environment variables can be lists of strings, seperated by ';'. This is typically used for the <code class="computeroutput">PATH</code> variable.</p>
<p>By default the environment will be inherited from the launching process, which is also true if environment are modified with this initializer.</p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="namespaceboost_1_1process_1env_details"></a>Details</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect2"><a href="env.html#namespaceboost_1_1process_1env_operations">Operations</a></span></dt>
<dt><span class="sect2"><a href="env.html#namespaceboost_1_1process_1env_example">Example</a></span></dt>
</dl></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="namespaceboost_1_1process_1env_operations"></a>Operations</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_set_var">Setting variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_append_var">Append variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_reset">Reset variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_init">Initialize the environment</a></span></dt>
</dl></div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_set_var"></a>Setting variables</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_set_var_value">value</a></span></dt>
</dl></div>
<p>To set a variable <code class="computeroutput">id</code> the value <code class="computeroutput">value</code> the following syntax can be used.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">value</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="identifier">value</span><span class="special">)</span><span class="special">;</span>
</pre>
<p><code class="computeroutput">std::initializer_list</code> is among the allowed types, so the following syntax is also possible.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Creates the variable if it does not exist.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code> for both <code class="computeroutput">id</code> and <code class="computeroutput">value</code>.</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_set_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::initializer_list&lt;const char_type *&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::vector&lt;std::basic_string&lt;char_type&gt;&gt;</code></p></li>
</ul></div>
<p>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Using <code class="computeroutput">std::vector</code> or <code class="computeroutput">std::initializer_list</code></p></td></tr>
</table></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_append_var"></a>Append variables</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_append_var_id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_append_var_value">value</a></span></dt>
</dl></div>
<p>Appending means, that a variable will be interpreted as a To append a variable <code class="computeroutput">id</code> the value <code class="computeroutput">value</code> the following syntax can be used:</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">+=</span> <span class="identifier">value</span><span class="special">;</span>
</pre>
<p><code class="computeroutput">std::initializer_list</code> is among the allowed types, so the following syntax is also possible.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">+=</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Creates the variable if it does not exist.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code> for both <code class="computeroutput">id</code> and <code class="computeroutput">value</code>.</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_append_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_append_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::initializer_list&lt;const char_type *&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::vector&lt;std::basic_string&lt;char_type&gt;&gt;</code></p></li>
</ul></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_reset"></a>Reset variables</h4></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_reset_var_id">id</a></span></dt></dl></div>
<p>Reseting signle variables can be done in the following way:</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>This does not set the value empty, but removes it from the list.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code>:</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_reset_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_init"></a>Initialize the environment</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_init_var_id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_init_var_value">value</a></span></dt>
</dl></div>
<p>The whole environment can be initialized from an object of type  <a class="link" href="../../process/reference.html#boost.process.environment">boost::process::environment</a> </p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">=</span><span class="identifier">env</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">env</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The passed <code class="computeroutput">environment</code> can also be default-constructed to get an empty environment.</p></td></tr>
</table></div>
<p>
</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_init_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_init_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="computeroutput"><a class="link" href="basic_environment.html" title="Class template basic_environment">boost::process::basic_environment</a>&lt;char_type&gt;</code></p></li></ul></div>
<p>
</p>
</div>
</div>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="namespaceboost_1_1process_1env_example"></a>Example</h3></div></div></div>
<pre class="programlisting"><span class="identifier">spawn</span><span class="special">(</span><span class="string">"b2"</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"PATH"</span><span class="special">]</span><span class="special">+=</span><span class="string">"F:/boost"</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"SOME_VAR"</span><span class="special">]</span><span class="special">=</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"NEW_VAR"</span><span class="special">]</span><span class="special">=</span><span class="string">"VALUE"</span><span class="special">)</span><span class="special">;</span>
</pre>
<p>If the overload style should be done by passing an instance of  <a class="link" href="../../process/reference.html#boost.process.environment">boost::process::environment</a>  the above example would look like this.</p>
<pre class="programlisting"><span class="identifier">environment</span> <span class="identifier">e</span> <span class="special">=</span> <span class="identifier">this_process</span><span class="special">::</span><span class="identifier">environment</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">[</span><span class="string">"PATH"</span><span class="special">]</span>   <span class="special">+=</span> <span class="string">"F:/boost"</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="string">"SOME_VAR"</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">[</span><span class="string">"NEW_VAR"</span><span class="special">]</span> <span class="special">=</span> <span class="string">"VALUE"</span><span class="special">;</span>
<span class="identifier">spawn</span><span class="special">(</span><span class="string">"b2"</span><span class="special">,</span> <span class="identifier">e</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Passing an empty environment will cause undefined behaviour. </p></td></tr>
</table></div>
<p>
</p>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2006-2012 Julio M. Merino Vidal, Ilya Sokolov,
      Felipe Tanus, Jeff Flinn, Boris Schaeling<br>Copyright &#169; 2016 Klemens D. Morgenstern<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmd.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.env_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="basic_environment.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>