oxipng/doc/bitflags/__core/process/struct.Command.html
2016-05-04 10:41:29 -04:00

211 lines
No EOL
21 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `Command` struct in crate `bitflags`.">
<meta name="keywords" content="rust, rustlang, rust-lang, Command">
<title>bitflags::__core::process::Command - Rust</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'><a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>process</a></p><script>window.sidebarCurrent = {name: 'Command', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>process</a>::<wbr><a class='struct' href=''>Command</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a id='src-8328' class='srclink' href='https://doc.rust-lang.org/nightly/std/process/struct.Command.html?gotosrc=8328' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Command {
// some fields omitted
}</pre><span class="since">1.0.0</span><div class='docblock'><p>The <code>Command</code> type acts as a process builder, providing fine-grained control
over how a new process should be spawned. A default configuration can be
generated using <code>Command::new(program)</code>, where <code>program</code> gives a path to the
program to be executed. Additional builder methods allow the configuration
to be changed (for example, by adding arguments) prior to spawning:</p>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>Command</span>;
<span class='kw'>let</span> <span class='ident'>output</span> <span class='op'>=</span> <span class='ident'>Command</span>::<span class='ident'>new</span>(<span class='string'>&quot;sh&quot;</span>)
.<span class='ident'>arg</span>(<span class='string'>&quot;-c&quot;</span>)
.<span class='ident'>arg</span>(<span class='string'>&quot;echo hello&quot;</span>)
.<span class='ident'>output</span>()
.<span class='ident'>expect</span>(<span class='string'>&quot;failed to execute proces&quot;</span>);
<span class='kw'>let</span> <span class='ident'>hello</span> <span class='op'>=</span> <span class='ident'>output</span>.<span class='ident'>stdout</span>;</pre>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h3><div class='impl-items'><h4 id='method.new' class='method'><code>fn <a href='#method.new' class='fnname'>new</a>&lt;S&gt;(program: S) -&gt; <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where S: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;</span></code></h4>
<div class='docblock'><p>Constructs a new <code>Command</code> for launching the program at
path <code>program</code>, with the following default configuration:</p>
<ul>
<li>No arguments to the program</li>
<li>Inherit the current process&#39;s environment</li>
<li>Inherit the current process&#39;s working directory</li>
<li>Inherit stdin/stdout/stderr for <code>spawn</code> or <code>status</code>, but create pipes for <code>output</code></li>
</ul>
<p>Builder methods are provided to change these defaults and
otherwise configure the process.</p>
</div><h4 id='method.arg' class='method'><code>fn <a href='#method.arg' class='fnname'>arg</a>&lt;S&gt;(&amp;mut self, arg: S) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where S: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;</span></code></h4>
<div class='docblock'><p>Add an argument to pass to the program.</p>
</div><h4 id='method.args' class='method'><code>fn <a href='#method.args' class='fnname'>args</a>&lt;S&gt;(&amp;mut self, args: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&amp;[S]</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where S: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;</span></code></h4>
<div class='docblock'><p>Add multiple arguments to pass to the program.</p>
</div><h4 id='method.env' class='method'><code>fn <a href='#method.env' class='fnname'>env</a>&lt;K, V&gt;(&amp;mut self, key: K, val: V) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where V: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;, K: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;</span></code></h4>
<div class='docblock'><p>Inserts or updates an environment variable mapping.</p>
<p>Note that environment variable names are case-insensitive (but case-preserving) on Windows,
and case-sensitive on all other platforms.</p>
</div><h4 id='method.env_remove' class='method'><code>fn <a href='#method.env_remove' class='fnname'>env_remove</a>&lt;K&gt;(&amp;mut self, key: K) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where K: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/ffi/struct.OsStr.html' title='bitflags::__core::ffi::OsStr'>OsStr</a>&gt;</span></code></h4>
<div class='docblock'><p>Removes an environment variable mapping.</p>
</div><h4 id='method.env_clear' class='method'><code>fn <a href='#method.env_clear' class='fnname'>env_clear</a>(&amp;mut self) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<div class='docblock'><p>Clears the entire environment map for the child process.</p>
</div><h4 id='method.current_dir' class='method'><code>fn <a href='#method.current_dir' class='fnname'>current_dir</a>&lt;P&gt;(&amp;mut self, dir: P) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where P: <a class='trait' href='../../../bitflags/__core/convert/trait.AsRef.html' title='bitflags::__core::convert::AsRef'>AsRef</a>&lt;<a class='struct' href='../../../bitflags/__core/path/struct.Path.html' title='bitflags::__core::path::Path'>Path</a>&gt;</span></code></h4>
<div class='docblock'><p>Sets the working directory for the child process.</p>
</div><h4 id='method.stdin' class='method'><code>fn <a href='#method.stdin' class='fnname'>stdin</a>(&amp;mut self, cfg: <a class='struct' href='../../../bitflags/__core/process/struct.Stdio.html' title='bitflags::__core::process::Stdio'>Stdio</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<div class='docblock'><p>Configuration for the child process&#39;s stdin handle (file descriptor 0).</p>
</div><h4 id='method.stdout' class='method'><code>fn <a href='#method.stdout' class='fnname'>stdout</a>(&amp;mut self, cfg: <a class='struct' href='../../../bitflags/__core/process/struct.Stdio.html' title='bitflags::__core::process::Stdio'>Stdio</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<div class='docblock'><p>Configuration for the child process&#39;s stdout handle (file descriptor 1).</p>
</div><h4 id='method.stderr' class='method'><code>fn <a href='#method.stderr' class='fnname'>stderr</a>(&amp;mut self, cfg: <a class='struct' href='../../../bitflags/__core/process/struct.Stdio.html' title='bitflags::__core::process::Stdio'>Stdio</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<div class='docblock'><p>Configuration for the child process&#39;s stderr handle (file descriptor 2).</p>
</div><h4 id='method.spawn' class='method'><code>fn <a href='#method.spawn' class='fnname'>spawn</a>(&amp;mut self) -&gt; <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a>&lt;<a class='struct' href='../../../bitflags/__core/process/struct.Child.html' title='bitflags::__core::process::Child'>Child</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>&gt;</code></h4>
<div class='docblock'><p>Executes the command as a child process, returning a handle to it.</p>
<p>By default, stdin, stdout and stderr are inherited from the parent.</p>
</div><h4 id='method.output' class='method'><code>fn <a href='#method.output' class='fnname'>output</a>(&amp;mut self) -&gt; <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a>&lt;<a class='struct' href='../../../bitflags/__core/process/struct.Output.html' title='bitflags::__core::process::Output'>Output</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>&gt;</code></h4>
<div class='docblock'><p>Executes the command as a child process, waiting for it to finish and
collecting all of its output.</p>
<p>By default, stdin, stdout and stderr are captured (and used to
provide the resulting output).</p>
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>Command</span>;
<span class='kw'>let</span> <span class='ident'>output</span> <span class='op'>=</span> <span class='ident'>Command</span>::<span class='ident'>new</span>(<span class='string'>&quot;/bin/cat&quot;</span>).<span class='ident'>arg</span>(<span class='string'>&quot;file.txt&quot;</span>).<span class='ident'>output</span>()
.<span class='ident'>expect</span>(<span class='string'>&quot;failed to execute process&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;status: {}&quot;</span>, <span class='ident'>output</span>.<span class='ident'>status</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;stdout: {}&quot;</span>, <span class='ident'>String</span>::<span class='ident'>from_utf8_lossy</span>(<span class='kw-2'>&amp;</span><span class='ident'>output</span>.<span class='ident'>stdout</span>));
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;stderr: {}&quot;</span>, <span class='ident'>String</span>::<span class='ident'>from_utf8_lossy</span>(<span class='kw-2'>&amp;</span><span class='ident'>output</span>.<span class='ident'>stderr</span>));
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>status</span>.<span class='ident'>success</span>());</pre>
</div><h4 id='method.status' class='method'><code>fn <a href='#method.status' class='fnname'>status</a>(&amp;mut self) -&gt; <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a>&lt;<a class='struct' href='../../../bitflags/__core/process/struct.ExitStatus.html' title='bitflags::__core::process::ExitStatus'>ExitStatus</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>&gt;</code></h4>
<div class='docblock'><p>Executes a command as a child process, waiting for it to finish and
collecting its exit status.</p>
<p>By default, stdin, stdout and stderr are inherited from the parent.</p>
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>process</span>::<span class='ident'>Command</span>;
<span class='kw'>let</span> <span class='ident'>status</span> <span class='op'>=</span> <span class='ident'>Command</span>::<span class='ident'>new</span>(<span class='string'>&quot;/bin/cat&quot;</span>).<span class='ident'>arg</span>(<span class='string'>&quot;file.txt&quot;</span>).<span class='ident'>status</span>()
.<span class='ident'>expect</span>(<span class='string'>&quot;failed to execute process&quot;</span>);
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;process exited with: {}&quot;</span>, <span class='ident'>status</span>);
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>status</span>.<span class='ident'>success</span>());</pre>
</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl <a class='trait' href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html' title='bitflags::__core::os::ext::prelude::CommandExt'>CommandExt</a> for <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h3><div class='impl-items'><h4 id='method.uid' class='method'><code>fn <a href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html#tymethod.uid' class='fnname'>uid</a>(&amp;mut self, id: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u32.html'>u32</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<h4 id='method.gid' class='method'><code>fn <a href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html#tymethod.gid' class='fnname'>gid</a>(&amp;mut self, id: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u32.html'>u32</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<h4 id='method.session_leader' class='method'><code>fn <a href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html#tymethod.session_leader' class='fnname'>session_leader</a>(&amp;mut self, on: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.bool.html'>bool</a>) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h4>
<h4 id='method.before_exec' class='method'><code>fn <a href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html#tymethod.before_exec' class='fnname'>before_exec</a>&lt;F&gt;(&amp;mut self, f: F) -&gt; &amp;mut <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a> <span class='where'>where F: <a class='trait' href='../../../bitflags/__core/ops/trait.FnMut.html' title='bitflags::__core::ops::FnMut'>FnMut</a>() -&gt; <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a>&lt;<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>&gt; + <a class='trait' href='../../../bitflags/__core/marker/trait.Send.html' title='bitflags::__core::marker::Send'>Send</a> + <a class='trait' href='../../../bitflags/__core/marker/trait.Sync.html' title='bitflags::__core::marker::Sync'>Sync</a> + 'static</span></code></h4>
<h4 id='method.exec' class='method'><code>fn <a href='../../../bitflags/__core/os/ext/prelude/trait.CommandExt.html#tymethod.exec' class='fnname'>exec</a>(&amp;mut self) -&gt; <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a></code></h4>
</div><h3 class='impl'><code>impl <a class='trait' href='../../../bitflags/__core/fmt/trait.Debug.html' title='bitflags::__core::fmt::Debug'>Debug</a> for <a class='struct' href='../../../bitflags/__core/process/struct.Command.html' title='bitflags::__core::process::Command'>Command</a></code></h3><div class='impl-items'><h4 id='method.fmt' class='method'><code>fn <a href='../../../bitflags/__core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class='struct' href='../../../bitflags/__core/fmt/struct.Formatter.html' title='bitflags::__core::fmt::Formatter'>Formatter</a>) -&gt; <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a>&lt;<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/fmt/struct.Error.html' title='bitflags::__core::fmt::Error'>Error</a>&gt;</code></h4>
<div class='docblock'><p>Format the program and arguments of a Command for display. Any
non-utf8 data is lossily converted using the utf8 replacement
character.</p>
</div></div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "bitflags";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>