You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

786 lines
25 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>exec - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package exec</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "os/exec"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package exec runs external commands. It wraps os.StartProcess to make it
  69. easier to remap stdin and stdout, connect I/O with pipes, and do other
  70. adjustments.
  71. </p>
  72. <p>
  73. Note that the examples in this package assume a Unix system.
  74. They may not run on Windows, and they do not run in the Go Playground
  75. used by golang.org and godoc.org.
  76. </p>
  77. </div>
  78. </div>
  79. <div id="pkg-index" class="toggleVisible">
  80. <div class="collapsed">
  81. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  82. </div>
  83. <div class="expanded">
  84. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  85. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  86. <div id="manual-nav">
  87. <dl>
  88. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  89. <dd><a href="index.html#LookPath">func LookPath(file string) (string, error)</a></dd>
  90. <dd><a href="index.html#Cmd">type Cmd</a></dd>
  91. <dd>&nbsp; &nbsp; <a href="index.html#Command">func Command(name string, arg ...string) *Cmd</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.CombinedOutput">func (c *Cmd) CombinedOutput() ([]byte, error)</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.Output">func (c *Cmd) Output() ([]byte, error)</a></dd>
  94. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.Run">func (c *Cmd) Run() error</a></dd>
  95. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.Start">func (c *Cmd) Start() error</a></dd>
  96. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.StderrPipe">func (c *Cmd) StderrPipe() (io.ReadCloser, error)</a></dd>
  97. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.StdinPipe">func (c *Cmd) StdinPipe() (io.WriteCloser, error)</a></dd>
  98. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.StdoutPipe">func (c *Cmd) StdoutPipe() (io.ReadCloser, error)</a></dd>
  99. <dd>&nbsp; &nbsp; <a href="index.html#Cmd.Wait">func (c *Cmd) Wait() error</a></dd>
  100. <dd><a href="index.html#Error">type Error</a></dd>
  101. <dd>&nbsp; &nbsp; <a href="index.html#Error.Error">func (e *Error) Error() string</a></dd>
  102. <dd><a href="index.html#ExitError">type ExitError</a></dd>
  103. <dd>&nbsp; &nbsp; <a href="index.html#ExitError.Error">func (e *ExitError) Error() string</a></dd>
  104. <dd><a href="index.html#pkg-note-BUG">Bugs</a></dd>
  105. </dl>
  106. </div><!-- #manual-nav -->
  107. <div id="pkg-examples">
  108. <h4>Examples</h4>
  109. <dl>
  110. <dd><a class="exampleLink" href="index.html#example_Cmd_Output">Cmd.Output</a></dd>
  111. <dd><a class="exampleLink" href="index.html#example_Cmd_Start">Cmd.Start</a></dd>
  112. <dd><a class="exampleLink" href="index.html#example_Cmd_StdoutPipe">Cmd.StdoutPipe</a></dd>
  113. <dd><a class="exampleLink" href="index.html#example_Command">Command</a></dd>
  114. <dd><a class="exampleLink" href="index.html#example_LookPath">LookPath</a></dd>
  115. </dl>
  116. </div>
  117. <h4>Package files</h4>
  118. <p>
  119. <span style="font-size:90%">
  120. <a href="http://localhost:6060/src/os/exec/exec.go">exec.go</a>
  121. <a href="http://localhost:6060/src/os/exec/exec_posix.go">exec_posix.go</a>
  122. <a href="http://localhost:6060/src/os/exec/lp_unix.go">lp_unix.go</a>
  123. </span>
  124. </p>
  125. </div><!-- .expanded -->
  126. </div><!-- #pkg-index -->
  127. <div id="pkg-callgraph" class="toggle" style="display: none">
  128. <div class="collapsed">
  129. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  130. </div> <!-- .expanded -->
  131. <div class="expanded">
  132. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  133. <p>
  134. In the call graph viewer below, each node
  135. is a function belonging to this package
  136. and its children are the functions it
  137. calls&mdash;perhaps dynamically.
  138. </p>
  139. <p>
  140. The root nodes are the entry points of the
  141. package: functions that may be called from
  142. outside the package.
  143. There may be non-exported or anonymous
  144. functions among them if they are called
  145. dynamically from another package.
  146. </p>
  147. <p>
  148. Click a node to visit that function's source code.
  149. From there you can visit its callers by
  150. clicking its declaring <code>func</code>
  151. token.
  152. </p>
  153. <p>
  154. Functions may be omitted if they were
  155. determined to be unreachable in the
  156. particular programs or tests that were
  157. analyzed.
  158. </p>
  159. <!-- Zero means show all package entry points. -->
  160. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  161. </div>
  162. </div> <!-- #pkg-callgraph -->
  163. <h2 id="pkg-variables">Variables</h2>
  164. <pre>var <span id="ErrNotFound">ErrNotFound</span> = <a href="../../errors/index.html">errors</a>.<a href="../../errors/index.html#New">New</a>(&#34;executable file not found in $PATH&#34;)</pre>
  165. <p>
  166. ErrNotFound is the error resulting if a path search failed to find an executable file.
  167. </p>
  168. <h2 id="LookPath">func <a href="http://localhost:6060/src/os/exec/lp_unix.go?s=915:957#L23">LookPath</a></h2>
  169. <pre>func LookPath(file <a href="../../builtin/index.html#string">string</a>) (<a href="../../builtin/index.html#string">string</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  170. <p>
  171. LookPath searches for an executable binary named file
  172. in the directories named by the PATH environment variable.
  173. If file contains a slash, it is tried directly and the PATH is not consulted.
  174. The result may be an absolute path or a path relative to the current directory.
  175. </p>
  176. <div id="example_LookPath" class="toggle">
  177. <div class="collapsed">
  178. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  179. </div>
  180. <div class="expanded">
  181. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  182. <p>Code:</p>
  183. <pre class="code">
  184. path, err := exec.LookPath(&#34;fortune&#34;)
  185. if err != nil {
  186. log.Fatal(&#34;installing fortune is in your future&#34;)
  187. }
  188. fmt.Printf(&#34;fortune is available at %s\n&#34;, path)
  189. </pre>
  190. </div>
  191. </div>
  192. <h2 id="Cmd">type <a href="http://localhost:6060/src/os/exec/exec.go?s=1021:3661#L32">Cmd</a></h2>
  193. <pre>type Cmd struct {
  194. <span class="comment">// Path is the path of the command to run.</span>
  195. <span class="comment">//</span>
  196. <span class="comment">// This is the only field that must be set to a non-zero</span>
  197. <span class="comment">// value. If Path is relative, it is evaluated relative</span>
  198. <span class="comment">// to Dir.</span>
  199. Path <a href="../../builtin/index.html#string">string</a>
  200. <span class="comment">// Args holds command line arguments, including the command as Args[0].</span>
  201. <span class="comment">// If the Args field is empty or nil, Run uses {Path}.</span>
  202. <span class="comment">//</span>
  203. <span class="comment">// In typical use, both Path and Args are set by calling Command.</span>
  204. Args []<a href="../../builtin/index.html#string">string</a>
  205. <span class="comment">// Env specifies the environment of the process.</span>
  206. <span class="comment">// If Env is nil, Run uses the current process&#39;s environment.</span>
  207. Env []<a href="../../builtin/index.html#string">string</a>
  208. <span class="comment">// Dir specifies the working directory of the command.</span>
  209. <span class="comment">// If Dir is the empty string, Run runs the command in the</span>
  210. <span class="comment">// calling process&#39;s current directory.</span>
  211. Dir <a href="../../builtin/index.html#string">string</a>
  212. <span class="comment">// Stdin specifies the process&#39;s standard input.</span>
  213. <span class="comment">// If Stdin is nil, the process reads from the null device (os.DevNull).</span>
  214. <span class="comment">// If Stdin is an *os.File, the process&#39;s standard input is connected</span>
  215. <span class="comment">// directly to that file.</span>
  216. <span class="comment">// Otherwise, during the execution of the command a separate</span>
  217. <span class="comment">// goroutine reads from Stdin and delivers that data to the command</span>
  218. <span class="comment">// over a pipe. In this case, Wait does not complete until the goroutine</span>
  219. <span class="comment">// stops copying, either because it has reached the end of Stdin</span>
  220. <span class="comment">// (EOF or a read error) or because writing to the pipe returned an error.</span>
  221. Stdin <a href="../../io/index.html">io</a>.<a href="../../io/index.html#Reader">Reader</a>
  222. <span class="comment">// Stdout and Stderr specify the process&#39;s standard output and error.</span>
  223. <span class="comment">//</span>
  224. <span class="comment">// If either is nil, Run connects the corresponding file descriptor</span>
  225. <span class="comment">// to the null device (os.DevNull).</span>
  226. <span class="comment">//</span>
  227. <span class="comment">// If Stdout and Stderr are the same writer, at most one</span>
  228. <span class="comment">// goroutine at a time will call Write.</span>
  229. Stdout <a href="../../io/index.html">io</a>.<a href="../../io/index.html#Writer">Writer</a>
  230. Stderr <a href="../../io/index.html">io</a>.<a href="../../io/index.html#Writer">Writer</a>
  231. <span class="comment">// ExtraFiles specifies additional open files to be inherited by the</span>
  232. <span class="comment">// new process. It does not include standard input, standard output, or</span>
  233. <span class="comment">// standard error. If non-nil, entry i becomes file descriptor 3+i.</span>
  234. <span class="comment">//</span>
  235. <span class="comment">// BUG(rsc): On OS X 10.6, child processes may sometimes inherit unwanted fds.</span>
  236. <span class="comment">// https://golang.org/issue/2603</span>
  237. ExtraFiles []*<a href="../index.html">os</a>.<a href="../index.html#File">File</a>
  238. <span class="comment">// SysProcAttr holds optional, operating system-specific attributes.</span>
  239. <span class="comment">// Run passes it to os.StartProcess as the os.ProcAttr&#39;s Sys field.</span>
  240. SysProcAttr *<a href="../../syscall/index.html">syscall</a>.<a href="../../syscall/index.html#SysProcAttr">SysProcAttr</a>
  241. <span class="comment">// Process is the underlying process, once started.</span>
  242. Process *<a href="../index.html">os</a>.<a href="../index.html#Process">Process</a>
  243. <span class="comment">// ProcessState contains information about an exited process,</span>
  244. <span class="comment">// available after a call to Wait or Run.</span>
  245. ProcessState *<a href="../index.html">os</a>.<a href="../index.html#ProcessState">ProcessState</a>
  246. <span class="comment">// contains filtered or unexported fields</span>
  247. }</pre>
  248. <p>
  249. Cmd represents an external command being prepared or run.
  250. </p>
  251. <p>
  252. A Cmd cannot be reused after calling its Run, Output or CombinedOutput
  253. methods.
  254. </p>
  255. <h3 id="Command">func <a href="http://localhost:6060/src/os/exec/exec.go?s=4176:4221#L116">Command</a></h3>
  256. <pre>func Command(name <a href="../../builtin/index.html#string">string</a>, arg ...<a href="../../builtin/index.html#string">string</a>) *<a href="index.html#Cmd">Cmd</a></pre>
  257. <p>
  258. Command returns the Cmd struct to execute the named program with
  259. the given arguments.
  260. </p>
  261. <p>
  262. It sets only the Path and Args in the returned structure.
  263. </p>
  264. <p>
  265. If name contains no path separators, Command uses LookPath to
  266. resolve the path to a complete name if possible. Otherwise it uses
  267. name directly.
  268. </p>
  269. <p>
  270. The returned Cmd&#39;s Args field is constructed from the command name
  271. followed by the elements of arg, so arg should not include the
  272. command name itself. For example, Command(&#34;echo&#34;, &#34;hello&#34;)
  273. </p>
  274. <div id="example_Command" class="toggle">
  275. <div class="collapsed">
  276. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  277. </div>
  278. <div class="expanded">
  279. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  280. <p>Code:</p>
  281. <pre class="code">
  282. cmd := exec.Command(&#34;tr&#34;, &#34;a-z&#34;, &#34;A-Z&#34;)
  283. cmd.Stdin = strings.NewReader(&#34;some input&#34;)
  284. var out bytes.Buffer
  285. cmd.Stdout = &amp;out
  286. err := cmd.Run()
  287. if err != nil {
  288. log.Fatal(err)
  289. }
  290. fmt.Printf(&#34;in all caps: %q\n&#34;, out.String())
  291. </pre>
  292. </div>
  293. </div>
  294. <h3 id="Cmd.CombinedOutput">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=11924:11970#L433">CombinedOutput</a></h3>
  295. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) CombinedOutput() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  296. <p>
  297. CombinedOutput runs the command and returns its combined standard
  298. output and standard error.
  299. </p>
  300. <h3 id="Cmd.Output">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=11387:11425#L410">Output</a></h3>
  301. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) Output() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  302. <p>
  303. Output runs the command and returns its standard output.
  304. Any returned error will usually be of type *ExitError.
  305. If c.Stderr was nil, Output populates ExitError.Stderr.
  306. </p>
  307. <div id="example_Cmd_Output" class="toggle">
  308. <div class="collapsed">
  309. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  310. </div>
  311. <div class="expanded">
  312. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  313. <p>Code:</p>
  314. <pre class="code">
  315. out, err := exec.Command(&#34;date&#34;).Output()
  316. if err != nil {
  317. log.Fatal(err)
  318. }
  319. fmt.Printf(&#34;The date is %s\n&#34;, out)
  320. </pre>
  321. </div>
  322. </div>
  323. <h3 id="Cmd.Run">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=7135:7160#L248">Run</a></h3>
  324. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) Run() <a href="../../builtin/index.html#error">error</a></pre>
  325. <p>
  326. Run starts the specified command and waits for it to complete.
  327. </p>
  328. <p>
  329. The returned error is nil if the command runs, has no problems
  330. copying stdin, stdout, and stderr, and exits with a zero exit
  331. status.
  332. </p>
  333. <p>
  334. If the command fails to run or doesn&#39;t complete successfully, the
  335. error is of type *ExitError. Other error types may be
  336. returned for I/O problems.
  337. </p>
  338. <h3 id="Cmd.Start">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=8166:8193#L285">Start</a></h3>
  339. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) Start() <a href="../../builtin/index.html#error">error</a></pre>
  340. <p>
  341. Start starts the specified command but does not wait for it to complete.
  342. </p>
  343. <p>
  344. The Wait method will return the exit code and release associated resources
  345. once the command exits.
  346. </p>
  347. <div id="example_Cmd_Start" class="toggle">
  348. <div class="collapsed">
  349. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  350. </div>
  351. <div class="expanded">
  352. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  353. <p>Code:</p>
  354. <pre class="code">
  355. cmd := exec.Command(&#34;sleep&#34;, &#34;5&#34;)
  356. err := cmd.Start()
  357. if err != nil {
  358. log.Fatal(err)
  359. }
  360. log.Printf(&#34;Waiting for command to finish...&#34;)
  361. err = cmd.Wait()
  362. log.Printf(&#34;Command finished with error: %v&#34;, err)
  363. </pre>
  364. </div>
  365. </div>
  366. <h3 id="Cmd.StderrPipe">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=14580:14629#L520">StderrPipe</a></h3>
  367. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) StderrPipe() (<a href="../../io/index.html">io</a>.<a href="../../io/index.html#ReadCloser">ReadCloser</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  368. <p>
  369. StderrPipe returns a pipe that will be connected to the command&#39;s
  370. standard error when the command starts.
  371. </p>
  372. <p>
  373. Wait will close the pipe after seeing the command exit, so most callers
  374. need not close the pipe themselves; however, an implication is that
  375. it is incorrect to call Wait before all reads from the pipe have completed.
  376. For the same reason, it is incorrect to use Run when using StderrPipe.
  377. See the StdoutPipe example for idiomatic usage.
  378. </p>
  379. <h3 id="Cmd.StdinPipe">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=12597:12646#L453">StdinPipe</a></h3>
  380. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) StdinPipe() (<a href="../../io/index.html">io</a>.<a href="../../io/index.html#WriteCloser">WriteCloser</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  381. <p>
  382. StdinPipe returns a pipe that will be connected to the command&#39;s
  383. standard input when the command starts.
  384. The pipe will be closed automatically after Wait sees the command exit.
  385. A caller need only call Close to force the pipe to close sooner.
  386. For example, if the command being run will not exit until standard input
  387. is closed, the caller must close the pipe.
  388. </p>
  389. <h3 id="Cmd.StdoutPipe">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=13694:13743#L495">StdoutPipe</a></h3>
  390. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) StdoutPipe() (<a href="../../io/index.html">io</a>.<a href="../../io/index.html#ReadCloser">ReadCloser</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  391. <p>
  392. StdoutPipe returns a pipe that will be connected to the command&#39;s
  393. standard output when the command starts.
  394. </p>
  395. <p>
  396. Wait will close the pipe after seeing the command exit, so most callers
  397. need not close the pipe themselves; however, an implication is that
  398. it is incorrect to call Wait before all reads from the pipe have completed.
  399. For the same reason, it is incorrect to call Run when using StdoutPipe.
  400. See the example for idiomatic usage.
  401. </p>
  402. <div id="example_Cmd_StdoutPipe" class="toggle">
  403. <div class="collapsed">
  404. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  405. </div>
  406. <div class="expanded">
  407. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  408. <p>Code:</p>
  409. <pre class="code">
  410. cmd := exec.Command(&#34;echo&#34;, &#34;-n&#34;, `{&#34;Name&#34;: &#34;Bob&#34;, &#34;Age&#34;: 32}`)
  411. stdout, err := cmd.StdoutPipe()
  412. if err != nil {
  413. log.Fatal(err)
  414. }
  415. if err := cmd.Start(); err != nil {
  416. log.Fatal(err)
  417. }
  418. var person struct {
  419. Name string
  420. Age int
  421. }
  422. if err := json.NewDecoder(stdout).Decode(&amp;person); err != nil {
  423. log.Fatal(err)
  424. }
  425. if err := cmd.Wait(); err != nil {
  426. log.Fatal(err)
  427. }
  428. fmt.Printf(&#34;%s is %d years old\n&#34;, person.Name, person.Age)
  429. </pre>
  430. </div>
  431. </div>
  432. <h3 id="Cmd.Wait">func (*Cmd) <a href="http://localhost:6060/src/os/exec/exec.go?s=10671:10697#L378">Wait</a></h3>
  433. <pre>func (c *<a href="index.html#Cmd">Cmd</a>) Wait() <a href="../../builtin/index.html#error">error</a></pre>
  434. <p>
  435. Wait waits for the command to exit.
  436. It must have been started by Start.
  437. </p>
  438. <p>
  439. The returned error is nil if the command runs, has no problems
  440. copying stdin, stdout, and stderr, and exits with a zero exit
  441. status.
  442. </p>
  443. <p>
  444. If the command fails to run or doesn&#39;t complete successfully, the
  445. error is of type *ExitError. Other error types may be
  446. returned for I/O problems.
  447. </p>
  448. <p>
  449. If c.Stdin is not an *os.File, Wait also waits for the I/O loop
  450. copying from c.Stdin into the process&#39;s standard input
  451. to complete.
  452. </p>
  453. <p>
  454. Wait releases any resources associated with the Cmd.
  455. </p>
  456. <h2 id="Error">type <a href="http://localhost:6060/src/os/exec/exec.go?s=723:769#L19">Error</a></h2>
  457. <pre>type Error struct {
  458. Name <a href="../../builtin/index.html#string">string</a>
  459. Err <a href="../../builtin/index.html#error">error</a>
  460. }</pre>
  461. <p>
  462. Error records the name of a binary that failed to be executed
  463. and the reason it failed.
  464. </p>
  465. <h3 id="Error.Error">func (*Error) <a href="http://localhost:6060/src/os/exec/exec.go?s=771:801#L24">Error</a></h3>
  466. <pre>func (e *<a href="index.html#Error">Error</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  467. <h2 id="ExitError">type <a href="http://localhost:6060/src/os/exec/exec.go?s=9496:10012#L342">ExitError</a></h2>
  468. <pre>type ExitError struct {
  469. *<a href="../index.html">os</a>.<a href="../index.html#ProcessState">ProcessState</a>
  470. <span class="comment">// Stderr holds a subset of the standard error output from the</span>
  471. <span class="comment">// Cmd.Output method if standard error was not otherwise being</span>
  472. <span class="comment">// collected.</span>
  473. <span class="comment">//</span>
  474. <span class="comment">// If the error output is long, Stderr may contain only a prefix</span>
  475. <span class="comment">// and suffix of the output, with the middle replaced with</span>
  476. <span class="comment">// text about the number of omitted bytes.</span>
  477. <span class="comment">//</span>
  478. <span class="comment">// Stderr is provided for debugging, for inclusion in error messages.</span>
  479. <span class="comment">// Users with other needs should redirect Cmd.Stderr as needed.</span>
  480. Stderr []<a href="../../builtin/index.html#byte">byte</a>
  481. }</pre>
  482. <p>
  483. An ExitError reports an unsuccessful exit by a command.
  484. </p>
  485. <h3 id="ExitError.Error">func (*ExitError) <a href="http://localhost:6060/src/os/exec/exec.go?s=10014:10048#L358">Error</a></h3>
  486. <pre>func (e *<a href="index.html#ExitError">ExitError</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  487. <h2 id="pkg-note-BUG">Bugs</h2>
  488. <ul style="list-style: none; padding: 0;">
  489. <li><a href="http://localhost:6060/src/os/exec/exec.go?s=2867:2979#L80">&#x261e;</a> On OS X 10.6, child processes may sometimes inherit unwanted fds.
  490. https://golang.org/issue/2603
  491. </li>
  492. </ul>
  493. <div id="footer">
  494. Build version go1.6.<br>
  495. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  496. the content of this page is licensed under the
  497. Creative Commons Attribution 3.0 License,
  498. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  499. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  500. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  501. </div>
  502. </div><!-- .container -->
  503. </div><!-- #page -->
  504. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  505. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  506. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  507. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  508. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  509. </body>
  510. </html>