osproc.html 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/osproc</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/osproc</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#Process" title="Process = ref ProcessObj">Process</a></li>
  57. <li><a class="reference" href="#ProcessOption" title="ProcessOption = enum
  58. poEchoCmd, ## Echo the command before execution.
  59. poUsePath, ## Asks system to search for executable using PATH environment
  60. ## variable.
  61. ## On Windows, this is the default.
  62. poEvalCommand, ## Pass `command` directly to the shell, without quoting.
  63. ## Use it only if `command` comes from trusted source.
  64. poStdErrToStdOut, ## Merge stdout and stderr to the stdout stream.
  65. poParentStreams, ## Use the parent's streams.
  66. poInteractive, ## Optimize the buffer handling for responsiveness for
  67. ## UI applications. Currently this only affects
  68. ## Windows: Named pipes are used so that you can peek
  69. ## at the process' output streams.
  70. poDaemon ## Windows: The program creates no Window.
  71. ## Unix: Start the program as a daemon. This is still
  72. ## work in progress!">ProcessOption</a></li>
  73. </ul>
  74. </details>
  75. </li>
  76. <li>
  77. <details open>
  78. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  79. <ul class="simple simple-toc-section">
  80. <ul class="simple nested-toc-section">close
  81. <li><a class="reference" href="#close%2CProcess" title="close(p: Process)">close(p: Process)</a></li>
  82. </ul>
  83. <ul class="simple nested-toc-section">countProcessors
  84. <li><a class="reference" href="#countProcessors" title="countProcessors(): int">countProcessors(): int</a></li>
  85. </ul>
  86. <ul class="simple nested-toc-section">errorHandle
  87. <li><a class="reference" href="#errorHandle%2CProcess" title="errorHandle(p: Process): FileHandle">errorHandle(p: Process): FileHandle</a></li>
  88. </ul>
  89. <ul class="simple nested-toc-section">errorStream
  90. <li><a class="reference" href="#errorStream%2CProcess" title="errorStream(p: Process): Stream">errorStream(p: Process): Stream</a></li>
  91. </ul>
  92. <ul class="simple nested-toc-section">execCmd
  93. <li><a class="reference" href="#execCmd%2Cstring" title="execCmd(command: string): int">execCmd(command: string): int</a></li>
  94. </ul>
  95. <ul class="simple nested-toc-section">execCmdEx
  96. <li><a class="reference" href="#execCmdEx%2Cstring%2Cset%5BProcessOption%5D%2CStringTableRef%2Cstring%2Cstring" title="execCmdEx(command: string;
  97. options: set[ProcessOption] = {poStdErrToStdOut, poUsePath};
  98. env: StringTableRef = nil; workingDir = &quot;&quot;; input = &quot;&quot;): tuple[
  99. output: string, exitCode: int]">execCmdEx(command: string;
  100. options: set[ProcessOption] = {poStdErrToStdOut, poUsePath};
  101. env: StringTableRef = nil; workingDir = &quot;&quot;; input = &quot;&quot;): tuple[
  102. output: string, exitCode: int]</a></li>
  103. </ul>
  104. <ul class="simple nested-toc-section">execProcess
  105. <li><a class="reference" href="#execProcess%2Cstring%2Cstring%2CopenArray%5Bstring%5D%2CStringTableRef%2Cset%5BProcessOption%5D" title="execProcess(command: string; workingDir: string = &quot;&quot;;
  106. args: openArray[string] = []; env: StringTableRef = nil; options: set[
  107. ProcessOption] = {poStdErrToStdOut, poUsePath, poEvalCommand}): string">execProcess(command: string; workingDir: string = &quot;&quot;;
  108. args: openArray[string] = []; env: StringTableRef = nil; options: set[
  109. ProcessOption] = {poStdErrToStdOut, poUsePath, poEvalCommand}): string</a></li>
  110. </ul>
  111. <ul class="simple nested-toc-section">execProcesses
  112. <li><a class="reference" href="#execProcesses%2CopenArray%5Bstring%5D%2Cproc%28int%29%2Cproc%28int%2CProcess%29" title="execProcesses(cmds: openArray[string];
  113. options = {poStdErrToStdOut, poParentStreams};
  114. n = countProcessors(); beforeRunEvent: proc (idx: int) = nil;
  115. afterRunEvent: proc (idx: int; p: Process) = nil): int">execProcesses(cmds: openArray[string];
  116. options = {poStdErrToStdOut, poParentStreams};
  117. n = countProcessors(); beforeRunEvent: proc (idx: int) = nil;
  118. afterRunEvent: proc (idx: int; p: Process) = nil): int</a></li>
  119. </ul>
  120. <ul class="simple nested-toc-section">hasData
  121. <li><a class="reference" href="#hasData%2CProcess" title="hasData(p: Process): bool">hasData(p: Process): bool</a></li>
  122. </ul>
  123. <ul class="simple nested-toc-section">inputHandle
  124. <li><a class="reference" href="#inputHandle%2CProcess" title="inputHandle(p: Process): FileHandle">inputHandle(p: Process): FileHandle</a></li>
  125. </ul>
  126. <ul class="simple nested-toc-section">inputStream
  127. <li><a class="reference" href="#inputStream%2CProcess" title="inputStream(p: Process): Stream">inputStream(p: Process): Stream</a></li>
  128. </ul>
  129. <ul class="simple nested-toc-section">kill
  130. <li><a class="reference" href="#kill%2CProcess" title="kill(p: Process)">kill(p: Process)</a></li>
  131. </ul>
  132. <ul class="simple nested-toc-section">outputHandle
  133. <li><a class="reference" href="#outputHandle%2CProcess" title="outputHandle(p: Process): FileHandle">outputHandle(p: Process): FileHandle</a></li>
  134. </ul>
  135. <ul class="simple nested-toc-section">outputStream
  136. <li><a class="reference" href="#outputStream%2CProcess" title="outputStream(p: Process): Stream">outputStream(p: Process): Stream</a></li>
  137. </ul>
  138. <ul class="simple nested-toc-section">peekableErrorStream
  139. <li><a class="reference" href="#peekableErrorStream%2CProcess" title="peekableErrorStream(p: Process): Stream">peekableErrorStream(p: Process): Stream</a></li>
  140. </ul>
  141. <ul class="simple nested-toc-section">peekableOutputStream
  142. <li><a class="reference" href="#peekableOutputStream%2CProcess" title="peekableOutputStream(p: Process): Stream">peekableOutputStream(p: Process): Stream</a></li>
  143. </ul>
  144. <ul class="simple nested-toc-section">peekExitCode
  145. <li><a class="reference" href="#peekExitCode%2CProcess" title="peekExitCode(p: Process): int">peekExitCode(p: Process): int</a></li>
  146. </ul>
  147. <ul class="simple nested-toc-section">processID
  148. <li><a class="reference" href="#processID%2CProcess" title="processID(p: Process): int">processID(p: Process): int</a></li>
  149. </ul>
  150. <ul class="simple nested-toc-section">readLines
  151. <li><a class="reference" href="#readLines%2CProcess" title="readLines(p: Process): (seq[string], int)">readLines(p: Process): (seq[string], int)</a></li>
  152. </ul>
  153. <ul class="simple nested-toc-section">resume
  154. <li><a class="reference" href="#resume%2CProcess" title="resume(p: Process)">resume(p: Process)</a></li>
  155. </ul>
  156. <ul class="simple nested-toc-section">running
  157. <li><a class="reference" href="#running%2CProcess" title="running(p: Process): bool">running(p: Process): bool</a></li>
  158. </ul>
  159. <ul class="simple nested-toc-section">startProcess
  160. <li><a class="reference" href="#startProcess%2Cstring%2Cstring%2CopenArray%5Bstring%5D%2CStringTableRef%2Cset%5BProcessOption%5D" title="startProcess(command: string; workingDir: string = &quot;&quot;;
  161. args: openArray[string] = []; env: StringTableRef = nil;
  162. options: set[ProcessOption] = {poStdErrToStdOut}): owned(Process)">startProcess(command: string; workingDir: string = &quot;&quot;;
  163. args: openArray[string] = []; env: StringTableRef = nil;
  164. options: set[ProcessOption] = {poStdErrToStdOut}): owned(Process)</a></li>
  165. </ul>
  166. <ul class="simple nested-toc-section">suspend
  167. <li><a class="reference" href="#suspend%2CProcess" title="suspend(p: Process)">suspend(p: Process)</a></li>
  168. </ul>
  169. <ul class="simple nested-toc-section">terminate
  170. <li><a class="reference" href="#terminate%2CProcess" title="terminate(p: Process)">terminate(p: Process)</a></li>
  171. </ul>
  172. <ul class="simple nested-toc-section">waitForExit
  173. <li><a class="reference" href="#waitForExit%2CProcess%2Cint" title="waitForExit(p: Process; timeout: int = -1): int">waitForExit(p: Process; timeout: int = -1): int</a></li>
  174. </ul>
  175. </ul>
  176. </details>
  177. </li>
  178. <li>
  179. <details open>
  180. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  181. <ul class="simple simple-toc-section">
  182. <ul class="simple nested-toc-section">lines
  183. <li><a class="reference" href="#lines.i%2CProcess" title="lines(p: Process; keepNewLines = false): string">lines(p: Process; keepNewLines = false): string</a></li>
  184. </ul>
  185. </ul>
  186. </details>
  187. </li>
  188. </ul>
  189. </div>
  190. <div class="nine columns" id="content">
  191. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  192. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  193. <div id="tocRoot"></div>
  194. <p class="module-desc"><p>This module implements an advanced facility for executing OS processes and process communication.</p>
  195. <p><strong>See also:</strong></p>
  196. <ul class="simple"><li><a class="reference external" href="os.html">os module</a></li>
  197. <li><a class="reference external" href="streams.html">streams module</a></li>
  198. <li><a class="reference external" href="memfiles.html">memfiles module</a></li>
  199. </ul>
  200. </p>
  201. <div class="section" id="6">
  202. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  203. <dl class="item">
  204. <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="strtabs.html">strtabs</a>, <a class="reference external" href="streams.html">streams</a>, <a class="reference external" href="cpuinfo.html">cpuinfo</a>, <a class="reference external" href="streamwrapper.html">streamwrapper</a>, <a class="reference external" href="since.html">since</a>, <a class="reference external" href="posix.html">posix</a>, <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="times.html">times</a>, <a class="reference external" href="monotimes.html">monotimes</a>
  205. </dl>
  206. </div>
  207. <div class="section" id="7">
  208. <h1><a class="toc-backref" href="#7">Types</a></h1>
  209. <dl class="item">
  210. <div id="Process">
  211. <dt><pre><a href="osproc.html#Process"><span class="Identifier">Process</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">ProcessObj</span></pre></dt>
  212. <dd>
  213. Represents an operating system process.
  214. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L73" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  215. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L73" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  216. </dd>
  217. </div>
  218. <div id="ProcessOption">
  219. <dt><pre><a href="osproc.html#ProcessOption"><span class="Identifier">ProcessOption</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  220. <span class="Identifier">poEchoCmd</span><span class="Other">,</span> <span class="Comment">## Echo the command before execution.</span>
  221. <span class="Identifier">poUsePath</span><span class="Other">,</span> <span class="Comment">## Asks system to search for executable using PATH environment</span>
  222. <span class="Comment">## variable.</span>
  223. <span class="Comment">## On Windows, this is the default.</span>
  224. <span class="Identifier">poEvalCommand</span><span class="Other">,</span> <span class="Comment">## Pass `command` directly to the shell, without quoting.</span>
  225. <span class="Comment">## Use it only if `command` comes from trusted source.</span>
  226. <span class="Identifier">poStdErrToStdOut</span><span class="Other">,</span> <span class="Comment">## Merge stdout and stderr to the stdout stream.</span>
  227. <span class="Identifier">poParentStreams</span><span class="Other">,</span> <span class="Comment">## Use the parent's streams.</span>
  228. <span class="Identifier">poInteractive</span><span class="Other">,</span> <span class="Comment">## Optimize the buffer handling for responsiveness for</span>
  229. <span class="Comment">## UI applications. Currently this only affects</span>
  230. <span class="Comment">## Windows: Named pipes are used so that you can peek</span>
  231. <span class="Comment">## at the process' output streams.</span>
  232. <span class="Identifier">poDaemon</span> <span class="Comment">## Windows: The program creates no Window.</span>
  233. <span class="Comment">## Unix: Start the program as a daemon. This is still</span>
  234. <span class="Comment">## work in progress!</span></pre></dt>
  235. <dd>
  236. Options that can be passed to <a class="reference external" href="#startProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">startProcess proc</a>.
  237. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L41" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  238. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L41" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  239. </dd>
  240. </div>
  241. </dl>
  242. </div>
  243. <div class="section" id="12">
  244. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  245. <dl class="item">
  246. <div id="close-procs-all">
  247. <div id="close,Process">
  248. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CProcess"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span>
  249. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  250. <dd>
  251. When the process has finished executing, cleanup related handles.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  252. If the process has not finished executing, this will forcibly terminate the process. Doing so may result in zombie processes and <a class="reference external" href="https://stackoverflow.com/questions/27021641/how-to-fix-request-failed-on-channel-0">pty leaks</a>.</div>
  253. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L155" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  254. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L155" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  255. </dd>
  256. </div>
  257. </div>
  258. <div id="countProcessors-procs-all">
  259. <div id="countProcessors">
  260. <dt><pre><span class="Keyword">proc</span> <a href="#countProcessors"><span class="Identifier">countProcessors</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  261. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  262. <dd>
  263. Returns the number of the processors/cores the machine has. Returns 0 if it cannot be detected. It is implemented just calling <tt class="docutils literal"><span class="pre"><span class="Identifier">cpuinfo</span><span class="Operator">.</span><span class="Identifier">countProcessors</span></span></tt>.
  264. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L332" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  265. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L332" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  266. </dd>
  267. </div>
  268. </div>
  269. <div id="errorHandle-procs-all">
  270. <div id="errorHandle,Process">
  271. <dt><pre><span class="Keyword">proc</span> <a href="#errorHandle%2CProcess"><span class="Identifier">errorHandle</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  272. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  273. <dd>
  274. Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s error file handle for reading from.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  275. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">FileHandle</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  276. <p>See also:</p>
  277. <ul class="simple"><li><a class="reference external" href="#inputHandle,Process">inputHandle proc</a></li>
  278. <li><a class="reference external" href="#outputHandle,Process">outputHandle proc</a></li>
  279. </ul>
  280. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L320" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  281. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L320" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  282. </dd>
  283. </div>
  284. </div>
  285. <div id="errorStream-procs-all">
  286. <div id="errorStream,Process">
  287. <dt><pre><span class="Keyword">proc</span> <a href="#errorStream%2CProcess"><span class="Identifier">errorStream</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  288. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  289. <dd>
  290. <p>Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s error stream for reading from.</p>
  291. <p>You cannot perform peek/write/setOption operations to this stream. Use <a class="reference external" href="#peekableErrorStream,Process">peekableErrorStream proc</a> if you need to peek stream.</p>
  292. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  293. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">Stream</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  294. <p>See also:</p>
  295. <ul class="simple"><li><a class="reference external" href="#inputStream,Process">inputStream proc</a></li>
  296. <li><a class="reference external" href="#outputStream,Process">outputStream proc</a></li>
  297. </ul>
  298. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L258" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  299. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L258" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  300. </dd>
  301. </div>
  302. </div>
  303. <div id="execCmd-procs-all">
  304. <div id="execCmd,string">
  305. <dt><pre><span class="Keyword">proc</span> <a href="#execCmd%2Cstring"><span class="Identifier">execCmd</span></a><span class="Other">(</span><span class="Identifier">command</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
  306. <a href="exceptions.html#ExecIOEffect"><span class="Identifier">ExecIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  307. <dd>
  308. <p>Executes <tt class="docutils literal"><span class="pre">command</span></tt> and returns its error code.</p>
  309. <p>Standard input, output, error streams are inherited from the calling process. This operation is also often called <span id="system_1">system</span>.</p>
  310. <p>See also:</p>
  311. <ul class="simple"><li><a class="reference external" href="#execCmdEx,string,set[ProcessOption],StringTableRef,string,string">execCmdEx proc</a></li>
  312. <li><a class="reference external" href="#startProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">startProcess proc</a></li>
  313. <li><a class="reference external" href="#execProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">execProcess proc</a></li>
  314. </ul>
  315. <p>Example:</p>
  316. <p><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">errC</span> <span class="Operator">=</span> <span class="Identifier">execCmd</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim c -r mytestfile.nim&quot;</span><span class="Punctuation">)</span></pre></p>
  317. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L101" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  318. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L101" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  319. </dd>
  320. </div>
  321. </div>
  322. <div id="execCmdEx-procs-all">
  323. <div id="execCmdEx,string,set[ProcessOption],StringTableRef,string,string">
  324. <dt><pre><span class="Keyword">proc</span> <a href="#execCmdEx%2Cstring%2Cset%5BProcessOption%5D%2CStringTableRef%2Cstring%2Cstring"><span class="Identifier">execCmdEx</span></a><span class="Other">(</span><span class="Identifier">command</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  325. <span class="Identifier">options</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="osproc.html#ProcessOption"><span class="Identifier">ProcessOption</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">poStdErrToStdOut</span><span class="Other">,</span> <span class="Identifier">poUsePath</span><span class="Other">}</span><span class="Other">;</span>
  326. <span class="Identifier">env</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span> <span class="Identifier">workingDir</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span> <span class="Identifier">input</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span>
  327. <span class="Identifier">output</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">exitCode</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
  328. <a href="exceptions.html#ExecIOEffect"><span class="Identifier">ExecIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  329. <dd>
  330. <p>A convenience proc that runs the <tt class="docutils literal"><span class="pre"><span class="Identifier">command</span></span></tt>, and returns its <tt class="docutils literal"><span class="pre"><span class="Identifier">output</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">exitCode</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">env</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">workingDir</span></span></tt> params behave as for <tt class="docutils literal"><span class="pre"><span class="Identifier">startProcess</span></span></tt>. If <tt class="docutils literal"><span class="pre"><span class="Identifier">input</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">&gt;</span> <span class="DecNumber">0</span></span></tt>, it is passed as stdin.</p>
  331. <p>Note: this could block if <tt class="docutils literal"><span class="pre"><span class="Identifier">input</span><span class="Operator">.</span><span class="Identifier">len</span></span></tt> is greater than your OS's maximum pipe buffer size.</p>
  332. <p>See also:</p>
  333. <ul class="simple"><li><a class="reference external" href="#execCmd,string">execCmd proc</a></li>
  334. <li><a class="reference external" href="#startProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">startProcess proc</a></li>
  335. <li><a class="reference external" href="#execProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">execProcess proc</a></li>
  336. </ul>
  337. <p>Example:</p>
  338. <p><pre class="listing"><span class="Keyword">var</span> <span class="Identifier">result</span> <span class="Operator">=</span> <span class="Identifier">execCmdEx</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim r --hints:off -&quot;</span><span class="Punctuation">,</span> <span class="Identifier">options</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="Punctuation">}</span><span class="Punctuation">,</span> <span class="Identifier">input</span> <span class="Operator">=</span> <span class="StringLit">&quot;echo 3*4&quot;</span><span class="Punctuation">)</span>
  339. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">strutils</span><span class="Punctuation">,</span> <span class="Identifier">strtabs</span><span class="Punctuation">]</span>
  340. <span class="Identifier">stripLineEnd</span><span class="Punctuation">(</span><span class="Identifier">result</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Comment">## portable way to remove trailing newline, if any</span>
  341. <span class="Identifier">doAssert</span> <span class="Identifier">result</span> <span class="Operator">==</span> <span class="Punctuation">(</span><span class="StringLit">&quot;12&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span>
  342. <span class="Identifier">doAssert</span> <span class="Identifier">execCmdEx</span><span class="Punctuation">(</span><span class="StringLit">&quot;ls --nonexistent&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">exitCode</span> <span class="Operator">!=</span> <span class="DecNumber">0</span>
  343. <span class="Keyword">when</span> <span class="Identifier">defined</span><span class="Punctuation">(</span><span class="Identifier">posix</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  344. <span class="Identifier">assert</span> <span class="Identifier">execCmdEx</span><span class="Punctuation">(</span><span class="StringLit">&quot;echo $FO&quot;</span><span class="Punctuation">,</span> <span class="Identifier">env</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;FO&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;B&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Punctuation">(</span><span class="StringLit">&quot;B</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span>
  345. <span class="Identifier">assert</span> <span class="Identifier">execCmdEx</span><span class="Punctuation">(</span><span class="StringLit">&quot;echo $PWD&quot;</span><span class="Punctuation">,</span> <span class="Identifier">workingDir</span> <span class="Operator">=</span> <span class="StringLit">&quot;/&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Punctuation">(</span><span class="StringLit">&quot;/</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span></pre></p>
  346. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L1522" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  347. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L1522" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  348. </dd>
  349. </div>
  350. </div>
  351. <div id="execProcess-procs-all">
  352. <div id="execProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">
  353. <dt><pre><span class="Keyword">proc</span> <a href="#execProcess%2Cstring%2Cstring%2CopenArray%5Bstring%5D%2CStringTableRef%2Cset%5BProcessOption%5D"><span class="Identifier">execProcess</span></a><span class="Other">(</span><span class="Identifier">command</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">workingDir</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  354. <span class="Identifier">args</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">env</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span>
  355. <span class="Identifier">options</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="osproc.html#ProcessOption"><span class="Identifier">ProcessOption</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">poStdErrToStdOut</span><span class="Other">,</span> <span class="Identifier">poUsePath</span><span class="Other">,</span> <span class="Identifier">poEvalCommand</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  356. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">]</span><span class="Other">,</span>
  357. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ExecIOEffect"><span class="Identifier">ExecIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  358. <dd>
  359. A convenience procedure that executes <tt class="docutils literal"><span class="pre">command</span></tt> with <tt class="docutils literal"><span class="pre">startProcess</span></tt> and returns its output as a string.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  360. This function uses <tt class="docutils literal"><span class="pre"><span class="Identifier">poEvalCommand</span></span></tt> by default for backwards compatibility. Make sure to pass options explicitly.</div>
  361. <p>See also:</p>
  362. <ul class="simple"><li><a class="reference external" href="#startProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">startProcess proc</a></li>
  363. <li><a class="reference external" href="#execProcesses,openArray[string],proc(int),proc(int,Process)">execProcesses proc</a></li>
  364. <li><a class="reference external" href="#execCmd,string">execCmd proc</a></li>
  365. </ul>
  366. <p>Example:</p>
  367. <p><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">outp</span> <span class="Operator">=</span> <span class="Identifier">execProcess</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim&quot;</span><span class="Punctuation">,</span> <span class="Identifier">args</span><span class="Operator">=</span><span class="Punctuation">[</span><span class="StringLit">&quot;c&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;-r&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;mytestfile.nim&quot;</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">options</span><span class="Operator">=</span><span class="Punctuation">{</span><span class="Identifier">poUsePath</span><span class="Punctuation">}</span><span class="Punctuation">)</span>
  368. <span class="Keyword">let</span> <span class="Identifier">outp_shell</span> <span class="Operator">=</span> <span class="Identifier">execProcess</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim c -r mytestfile.nim&quot;</span><span class="Punctuation">)</span>
  369. <span class="Comment"># Note: outp may have an interleave of text from the nim compile</span>
  370. <span class="Comment"># and any output from mytestfile when it runs</span></pre></p>
  371. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L76" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  372. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L76" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  373. </dd>
  374. </div>
  375. </div>
  376. <div id="execProcesses-procs-all">
  377. <div id="execProcesses,openArray[string],proc(int),proc(int,Process)">
  378. <dt><pre><span class="Keyword">proc</span> <a href="#execProcesses%2CopenArray%5Bstring%5D%2Cproc%28int%29%2Cproc%28int%2CProcess%29"><span class="Identifier">execProcesses</span></a><span class="Other">(</span><span class="Identifier">cmds</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">;</span>
  379. <span class="Identifier">options</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">poStdErrToStdOut</span><span class="Other">,</span> <span class="Identifier">poParentStreams</span><span class="Other">}</span><span class="Other">;</span>
  380. <span class="Identifier">n</span> <span class="Other">=</span> <span class="Identifier">countProcessors</span><span class="Other">(</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">beforeRunEvent</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">idx</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span>
  381. <span class="Identifier">afterRunEvent</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">idx</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  382. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">]</span><span class="Other">,</span>
  383. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ExecIOEffect"><span class="Identifier">ExecIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">,</span> <a href="envvars.html#ReadEnvEffect"><span class="Identifier">ReadEnvEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  384. </span><span class="Identifier">effectsOf</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">beforeRunEvent</span><span class="Other">,</span> <span class="Identifier">afterRunEvent</span><span class="Other">]</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  385. <dd>
  386. <p>Executes the commands <tt class="docutils literal"><span class="pre"><span class="Identifier">cmds</span></span></tt> in parallel. Creates <tt class="docutils literal"><span class="pre"><span class="Identifier">n</span></span></tt> processes that execute in parallel.</p>
  387. <p>The highest (absolute) return value of all processes is returned. Runs <tt class="docutils literal"><span class="pre"><span class="Identifier">beforeRunEvent</span></span></tt> before running each command.</p>
  388. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L341" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  389. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  390. </dd>
  391. </div>
  392. </div>
  393. <div id="hasData-procs-all">
  394. <div id="hasData,Process">
  395. <dt><pre><span class="Keyword">proc</span> <a href="#hasData%2CProcess"><span class="Identifier">hasData</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  396. <dd>
  397. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L1512" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  398. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L1512" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  399. </dd>
  400. </div>
  401. </div>
  402. <div id="inputHandle-procs-all">
  403. <div id="inputHandle,Process">
  404. <dt><pre><span class="Keyword">proc</span> <a href="#inputHandle%2CProcess"><span class="Identifier">inputHandle</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  405. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  406. <dd>
  407. Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s input file handle for writing to.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  408. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">FileHandle</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  409. <p>See also:</p>
  410. <ul class="simple"><li><a class="reference external" href="#outputHandle,Process">outputHandle proc</a></li>
  411. <li><a class="reference external" href="#errorHandle,Process">errorHandle proc</a></li>
  412. </ul>
  413. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L296" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  414. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L296" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  415. </dd>
  416. </div>
  417. </div>
  418. <div id="inputStream-procs-all">
  419. <div id="inputStream,Process">
  420. <dt><pre><span class="Keyword">proc</span> <a href="#inputStream%2CProcess"><span class="Identifier">inputStream</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  421. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  422. <dd>
  423. Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s input stream for writing to.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  424. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">Stream</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  425. <p>See also:</p>
  426. <ul class="simple"><li><a class="reference external" href="#outputStream,Process">outputStream proc</a></li>
  427. <li><a class="reference external" href="#errorStream,Process">errorStream proc</a></li>
  428. </ul>
  429. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L234" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  430. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L234" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  431. </dd>
  432. </div>
  433. </div>
  434. <div id="kill-procs-all">
  435. <div id="kill,Process">
  436. <dt><pre><span class="Keyword">proc</span> <a href="#kill%2CProcess"><span class="Identifier">kill</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  437. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  438. <dd>
  439. <p>Kill the process <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>.</p>
  440. <p>On Posix OSes the procedure sends <tt class="docutils literal"><span class="pre">SIGKILL</span></tt> to the process. On Windows <tt class="docutils literal"><span class="pre">kill</span></tt> is simply an alias for <a class="reference external" href="#terminate,Process">terminate()</a>.</p>
  441. <p>See also:</p>
  442. <ul class="simple"><li><a class="reference external" href="#suspend,Process">suspend proc</a></li>
  443. <li><a class="reference external" href="#resume,Process">resume proc</a></li>
  444. <li><a class="reference external" href="#terminate,Process">terminate proc</a></li>
  445. <li><a class="reference external" href="posix_utils.html#sendSignal,Pid,int">posix_utils.sendSignal(pid: Pid, signal: int)</a></li>
  446. </ul>
  447. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L192" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  448. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L192" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  449. </dd>
  450. </div>
  451. </div>
  452. <div id="outputHandle-procs-all">
  453. <div id="outputHandle,Process">
  454. <dt><pre><span class="Keyword">proc</span> <a href="#outputHandle%2CProcess"><span class="Identifier">outputHandle</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  455. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  456. <dd>
  457. Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s output file handle for reading from.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  458. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">FileHandle</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  459. <p>See also:</p>
  460. <ul class="simple"><li><a class="reference external" href="#inputHandle,Process">inputHandle proc</a></li>
  461. <li><a class="reference external" href="#errorHandle,Process">errorHandle proc</a></li>
  462. </ul>
  463. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L308" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  464. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L308" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  465. </dd>
  466. </div>
  467. </div>
  468. <div id="outputStream-procs-all">
  469. <div id="outputStream,Process">
  470. <dt><pre><span class="Keyword">proc</span> <a href="#outputStream%2CProcess"><span class="Identifier">outputStream</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  471. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  472. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  473. <dd>
  474. <p>Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s output stream for reading from.</p>
  475. <p>You cannot perform peek/write/setOption operations to this stream. Use <a class="reference external" href="#peekableOutputStream,Process">peekableOutputStream proc</a> if you need to peek stream.</p>
  476. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  477. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">Stream</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  478. <p>See also:</p>
  479. <ul class="simple"><li><a class="reference external" href="#inputStream,Process">inputStream proc</a></li>
  480. <li><a class="reference external" href="#errorStream,Process">errorStream proc</a></li>
  481. </ul>
  482. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L244" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  483. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L244" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  484. </dd>
  485. </div>
  486. </div>
  487. <div id="peekableErrorStream-procs-all">
  488. <div id="peekableErrorStream,Process">
  489. <dt><pre><span class="Keyword">proc</span> <a href="#peekableErrorStream%2CProcess"><span class="Identifier">peekableErrorStream</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  490. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  491. <dd>
  492. <p>Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s error stream for reading from.</p>
  493. <p>You can run peek operation to returned stream.</p>
  494. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  495. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">Stream</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  496. <p>See also:</p>
  497. <ul class="simple"><li><a class="reference external" href="#errorStream,Process">errorStream proc</a></li>
  498. <li><a class="reference external" href="#peekableOutputStream,Process">peekableOutputStream proc</a></li>
  499. </ul>
  500. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L284" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  501. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L284" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  502. </dd>
  503. </div>
  504. </div>
  505. <div id="peekableOutputStream-procs-all">
  506. <div id="peekableOutputStream,Process">
  507. <dt><pre><span class="Keyword">proc</span> <a href="#peekableOutputStream%2CProcess"><span class="Identifier">peekableOutputStream</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  508. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  509. <dd>
  510. <p>Returns <tt class="docutils literal"><span class="pre">p</span></tt>'s output stream for reading from.</p>
  511. <p>You can peek returned stream.</p>
  512. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  513. The returned <tt class="docutils literal"><span class="pre"><span class="Identifier">Stream</span></span></tt> should not be closed manually as it is closed when closing the Process <tt class="docutils literal"><span class="pre">p</span></tt>.</div>
  514. <p>See also:</p>
  515. <ul class="simple"><li><a class="reference external" href="#outputStream,Process">outputStream proc</a></li>
  516. <li><a class="reference external" href="#peekableErrorStream,Process">peekableErrorStream proc</a></li>
  517. </ul>
  518. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L272" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  519. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L272" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  520. </dd>
  521. </div>
  522. </div>
  523. <div id="peekExitCode-procs-all">
  524. <div id="peekExitCode,Process">
  525. <dt><pre><span class="Keyword">proc</span> <a href="#peekExitCode%2CProcess"><span class="Identifier">peekExitCode</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  526. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  527. <dd>
  528. <p>Return <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> if the process is still running. Otherwise the process' exit code.</p>
  529. <p>On posix, if the process has exited because of a signal, 128 + signal number will be returned.</p>
  530. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L228" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  531. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L228" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  532. </dd>
  533. </div>
  534. </div>
  535. <div id="processID-procs-all">
  536. <div id="processID,Process">
  537. <dt><pre><span class="Keyword">proc</span> <a href="#processID%2CProcess"><span class="Identifier">processID</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  538. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  539. <dd>
  540. <p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>'s process ID.</p>
  541. <p>See also:</p>
  542. <ul class="simple"><li><a class="reference external" href="os.html#getCurrentProcessId">os.getCurrentProcessId proc</a></li>
  543. </ul>
  544. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L207" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  545. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L207" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  546. </dd>
  547. </div>
  548. </div>
  549. <div id="readLines-procs-all">
  550. <div id="readLines,Process">
  551. <dt><pre><span class="Keyword">proc</span> <a href="#readLines%2CProcess"><span class="Identifier">readLines</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.
  552. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  553. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  554. <dd>
  555. <p>Convenience function for working with <tt class="docutils literal"><span class="pre"><span class="Identifier">startProcess</span></span></tt> to read data from a background process.</p>
  556. <p>See also:</p>
  557. <ul class="simple"><li><a class="reference external" href="#lines.i,Process">lines iterator</a></li>
  558. </ul>
  559. <p>Example:</p>
  560. <p><pre class="listing"><span class="Keyword">const</span> <span class="Identifier">opts</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="Identifier">poUsePath</span><span class="Punctuation">,</span> <span class="Identifier">poDaemon</span><span class="Punctuation">,</span> <span class="Identifier">poStdErrToStdOut</span><span class="Punctuation">}</span>
  561. <span class="Keyword">var</span> <span class="Identifier">ps</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">Process</span><span class="Punctuation">]</span>
  562. <span class="Keyword">for</span> <span class="Identifier">prog</span> <span class="Keyword">in</span> <span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">:</span> <span class="Comment"># run 2 progs in parallel</span>
  563. <span class="Identifier">ps</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">startProcess</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="Punctuation">[</span><span class="StringLit">&quot;r&quot;</span><span class="Punctuation">,</span> <span class="Identifier">prog</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Keyword">nil</span><span class="Punctuation">,</span> <span class="Identifier">opts</span><span class="Punctuation">)</span>
  564. <span class="Keyword">for</span> <span class="Identifier">p</span> <span class="Keyword">in</span> <span class="Identifier">ps</span><span class="Punctuation">:</span>
  565. <span class="Keyword">let</span> <span class="Punctuation">(</span><span class="Identifier">lines</span><span class="Punctuation">,</span> <span class="Identifier">exCode</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">readLines</span>
  566. <span class="Keyword">if</span> <span class="Identifier">exCode</span> <span class="Operator">!=</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
  567. <span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">lines</span><span class="Punctuation">:</span> <span class="Identifier">echo</span> <span class="Identifier">line</span>
  568. <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">close</span></pre></p>
  569. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L489" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  570. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L489" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  571. </dd>
  572. </div>
  573. </div>
  574. <div id="resume-procs-all">
  575. <div id="resume,Process">
  576. <dt><pre><span class="Keyword">proc</span> <a href="#resume%2CProcess"><span class="Identifier">resume</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  577. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  578. <dd>
  579. <p>Resumes the process <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>.</p>
  580. <p>See also:</p>
  581. <ul class="simple"><li><a class="reference external" href="#suspend,Process">suspend proc</a></li>
  582. <li><a class="reference external" href="#terminate,Process">terminate proc</a></li>
  583. <li><a class="reference external" href="#kill,Process">kill proc</a></li>
  584. </ul>
  585. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L171" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  586. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L171" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  587. </dd>
  588. </div>
  589. </div>
  590. <div id="running-procs-all">
  591. <div id="running,Process">
  592. <dt><pre><span class="Keyword">proc</span> <a href="#running%2CProcess"><span class="Identifier">running</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span>
  593. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  594. <dd>
  595. Returns true if the process <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt> is still running. Returns immediately.
  596. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L204" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  597. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L204" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  598. </dd>
  599. </div>
  600. </div>
  601. <div id="startProcess-procs-all">
  602. <div id="startProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">
  603. <dt><pre><span class="Keyword">proc</span> <a href="#startProcess%2Cstring%2Cstring%2CopenArray%5Bstring%5D%2CStringTableRef%2Cset%5BProcessOption%5D"><span class="Identifier">startProcess</span></a><span class="Other">(</span><span class="Identifier">command</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">workingDir</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  604. <span class="Identifier">args</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">env</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span>
  605. <span class="Identifier">options</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="osproc.html#ProcessOption"><span class="Identifier">ProcessOption</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">poStdErrToStdOut</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
  606. <span class="Identifier">Process</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">]</span><span class="Other">,</span>
  607. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ExecIOEffect"><span class="Identifier">ExecIOEffect</span></a><span class="Other">,</span> <a href="envvars.html#ReadEnvEffect"><span class="Identifier">ReadEnvEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  608. <dd>
  609. <p>Starts a process. <tt class="docutils literal"><span class="pre"><span class="Identifier">Command</span></span></tt> is the executable file, <tt class="docutils literal"><span class="pre"><span class="Identifier">workingDir</span></span></tt> is the process's working directory. If <tt class="docutils literal"><span class="pre">workingDir == &quot;&quot;</span></tt> the current directory is used (default). <tt class="docutils literal"><span class="pre"><span class="Identifier">args</span></span></tt> are the command line arguments that are passed to the process. On many operating systems, the first command line argument is the name of the executable. <tt class="docutils literal"><span class="pre"><span class="Identifier">args</span></span></tt> should <em>not</em> contain this argument! <tt class="docutils literal"><span class="pre"><span class="Identifier">env</span></span></tt> is the environment that will be passed to the process. If <tt class="docutils literal"><span class="pre">env == nil</span></tt> (default) the environment is inherited of the parent process. <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> are additional flags that may be passed to <tt class="docutils literal"><span class="pre"><span class="Identifier">startProcess</span></span></tt>. See the documentation of <a class="reference external" href="#ProcessOption">ProcessOption</a> for the meaning of these flags.</p>
  610. <p>You need to <a class="reference external" href="#close,Process">close</a> the process when done.</p>
  611. <p>Note that you can't pass any <tt class="docutils literal"><span class="pre"><span class="Identifier">args</span></span></tt> if you use the option <tt class="docutils literal"><span class="pre">poEvalCommand</span></tt>, which invokes the system shell to run the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">command</span></span></tt>. In this situation you have to concatenate manually the contents of <tt class="docutils literal"><span class="pre"><span class="Identifier">args</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">command</span></span></tt> carefully escaping/quoting any special characters, since it will be passed <em>as is</em> to the system shell. Each system/shell may feature different escaping rules, so try to avoid this kind of shell invocation if possible as it leads to non portable software.</p>
  612. <p>Return value: The newly created process object. Nil is never returned, but <tt class="docutils literal"><span class="pre">OSError</span></tt> is raised in case of an error.</p>
  613. <p>See also:</p>
  614. <ul class="simple"><li><a class="reference external" href="#execProcesses,openArray[string],proc(int),proc(int,Process)">execProcesses proc</a></li>
  615. <li><a class="reference external" href="#execProcess,string,string,openArray[string],StringTableRef,set[ProcessOption]">execProcess proc</a></li>
  616. <li><a class="reference external" href="#execCmd,string">execCmd proc</a></li>
  617. </ul>
  618. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L120" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  619. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L120" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  620. </dd>
  621. </div>
  622. </div>
  623. <div id="suspend-procs-all">
  624. <div id="suspend,Process">
  625. <dt><pre><span class="Keyword">proc</span> <a href="#suspend%2CProcess"><span class="Identifier">suspend</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  626. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  627. <dd>
  628. <p>Suspends the process <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>.</p>
  629. <p>See also:</p>
  630. <ul class="simple"><li><a class="reference external" href="#resume,Process">resume proc</a></li>
  631. <li><a class="reference external" href="#terminate,Process">terminate proc</a></li>
  632. <li><a class="reference external" href="#kill,Process">kill proc</a></li>
  633. </ul>
  634. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L162" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  635. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L162" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  636. </dd>
  637. </div>
  638. </div>
  639. <div id="terminate-procs-all">
  640. <div id="terminate,Process">
  641. <dt><pre><span class="Keyword">proc</span> <a href="#terminate%2CProcess"><span class="Identifier">terminate</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  642. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  643. <dd>
  644. <p>Stop the process <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>.</p>
  645. <p>On Posix OSes the procedure sends <tt class="docutils literal"><span class="pre">SIGTERM</span></tt> to the process. On Windows the Win32 API function <tt class="docutils literal"><span class="pre">TerminateProcess()</span></tt> is called to stop the process.</p>
  646. <p>See also:</p>
  647. <ul class="simple"><li><a class="reference external" href="#suspend,Process">suspend proc</a></li>
  648. <li><a class="reference external" href="#resume,Process">resume proc</a></li>
  649. <li><a class="reference external" href="#kill,Process">kill proc</a></li>
  650. <li><a class="reference external" href="posix_utils.html#sendSignal,Pid,int">posix_utils.sendSignal(pid: Pid, signal: int)</a></li>
  651. </ul>
  652. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L179" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  653. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L179" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  654. </dd>
  655. </div>
  656. </div>
  657. <div id="waitForExit-procs-all">
  658. <div id="waitForExit,Process,int">
  659. <dt><pre><span class="Keyword">proc</span> <a href="#waitForExit%2CProcess%2Cint"><span class="Identifier">waitForExit</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">;</span> <span class="Identifier">timeout</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nosp$1&quot;</span><span class="Other">,</span>
  660. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  661. <dd>
  662. Waits for the process to finish and returns <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>'s error code.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  663. Be careful when using <tt class="docutils literal"><span class="pre"><span class="Identifier">waitForExit</span></span></tt> for processes created without <tt class="docutils literal"><span class="pre"><span class="Identifier">poParentStreams</span></span></tt> because they may fill output buffers, causing deadlock.</div>
  664. <p>On posix, if the process has exited because of a signal, 128 + signal number will be returned.</p>
  665. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  666. When working with <tt class="docutils literal"><span class="pre"><span class="Identifier">timeout</span></span></tt> parameters, remember that the value is typically expressed in milliseconds, and ensure that the correct unit of time is used to avoid unexpected behavior.</div>
  667. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L214" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  668. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L214" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  669. </dd>
  670. </div>
  671. </div>
  672. </dl>
  673. </div>
  674. <div class="section" id="15">
  675. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  676. <dl class="item">
  677. <div id="lines-iterators-all">
  678. <div id="lines.i,Process">
  679. <dt><pre><span class="Keyword">iterator</span> <a href="#lines.i%2CProcess"><span class="Identifier">lines</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="osproc.html#Process"><span class="Identifier">Process</span></a><span class="Other">;</span> <span class="Identifier">keepNewLines</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  680. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  681. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  682. <dd>
  683. <p>Convenience iterator for working with <tt class="docutils literal"><span class="pre"><span class="Identifier">startProcess</span></span></tt> to read data from a background process.</p>
  684. <p>See also:</p>
  685. <ul class="simple"><li><a class="reference external" href="#readLines,Process">readLines proc</a></li>
  686. </ul>
  687. <p>Example:</p>
  688. <p><pre class="listing"><span class="Keyword">const</span> <span class="Identifier">opts</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="Identifier">poUsePath</span><span class="Punctuation">,</span> <span class="Identifier">poDaemon</span><span class="Punctuation">,</span> <span class="Identifier">poStdErrToStdOut</span><span class="Punctuation">}</span>
  689. <span class="Keyword">var</span> <span class="Identifier">ps</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">Process</span><span class="Punctuation">]</span>
  690. <span class="Keyword">for</span> <span class="Identifier">prog</span> <span class="Keyword">in</span> <span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">:</span> <span class="Comment"># run 2 progs in parallel</span>
  691. <span class="Identifier">ps</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">startProcess</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="Punctuation">[</span><span class="StringLit">&quot;r&quot;</span><span class="Punctuation">,</span> <span class="Identifier">prog</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Keyword">nil</span><span class="Punctuation">,</span> <span class="Identifier">opts</span><span class="Punctuation">)</span>
  692. <span class="Keyword">for</span> <span class="Identifier">p</span> <span class="Keyword">in</span> <span class="Identifier">ps</span><span class="Punctuation">:</span>
  693. <span class="Keyword">var</span> <span class="Identifier">i</span> <span class="Operator">=</span> <span class="DecNumber">0</span>
  694. <span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">lines</span><span class="Punctuation">:</span>
  695. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  696. <span class="Identifier">i</span><span class="Operator">.</span><span class="Identifier">inc</span>
  697. <span class="Keyword">if</span> <span class="Identifier">i</span> <span class="Operator">&gt;</span> <span class="DecNumber">100</span><span class="Punctuation">:</span> <span class="Keyword">break</span>
  698. <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">close</span></pre></p>
  699. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/osproc.nim#L460" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  700. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/osproc.nim#L460" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  701. </dd>
  702. </div>
  703. </div>
  704. </dl>
  705. </div>
  706. </div>
  707. </div>
  708. <div class="twelve-columns footer">
  709. <span class="nim-sprite"></span>
  710. <br>
  711. <small style="color: var(--hint);">Made with Nim. Generated: 2025-03-15 14:13:21 UTC</small>
  712. </div>
  713. </div>
  714. </div>
  715. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  716. </body>
  717. </html>