m06_task3.js 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. package/.idea/.name +1 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +10 -0
  3. package/.idea/jsLibraryMappings.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/node_lab_6.iml +12 -0
  6. package/06_task2.html +73 -0
  7. package/06_task2.js +52 -0
  8. package/06_task3.js +3 -0
  9. package/06_task4.js +3 -0
  10. package/m06_task3.js +28 -0
  11. package/package/index.js +28 -0
  12. package/package/node_modules/.package-lock.json +31 -0
  13. package/package/node_modules/@types/node/LICENSE +21 -0
  14. package/package/node_modules/@types/node/README.md +16 -0
  15. package/package/node_modules/@types/node/assert/strict.d.ts +8 -0
  16. package/package/node_modules/@types/node/assert.d.ts +961 -0
  17. package/package/node_modules/@types/node/async_hooks.d.ts +501 -0
  18. package/package/node_modules/@types/node/buffer.d.ts +2258 -0
  19. package/package/node_modules/@types/node/child_process.d.ts +1369 -0
  20. package/package/node_modules/@types/node/cluster.d.ts +410 -0
  21. package/package/node_modules/@types/node/console.d.ts +412 -0
  22. package/package/node_modules/@types/node/constants.d.ts +18 -0
  23. package/package/node_modules/@types/node/crypto.d.ts +3964 -0
  24. package/package/node_modules/@types/node/dgram.d.ts +545 -0
  25. package/package/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
  26. package/package/node_modules/@types/node/dns/promises.d.ts +370 -0
  27. package/package/node_modules/@types/node/dns.d.ts +659 -0
  28. package/package/node_modules/@types/node/dom-events.d.ts +126 -0
  29. package/package/node_modules/@types/node/domain.d.ts +170 -0
  30. package/package/node_modules/@types/node/events.d.ts +678 -0
  31. package/package/node_modules/@types/node/fs/promises.d.ts +1138 -0
  32. package/package/node_modules/@types/node/fs.d.ts +3872 -0
  33. package/package/node_modules/@types/node/globals.d.ts +300 -0
  34. package/package/node_modules/@types/node/globals.global.d.ts +1 -0
  35. package/package/node_modules/@types/node/http.d.ts +1614 -0
  36. package/package/node_modules/@types/node/http2.d.ts +2134 -0
  37. package/package/node_modules/@types/node/https.d.ts +541 -0
  38. package/package/node_modules/@types/node/index.d.ts +133 -0
  39. package/package/node_modules/@types/node/inspector.d.ts +2741 -0
  40. package/package/node_modules/@types/node/module.d.ts +114 -0
  41. package/package/node_modules/@types/node/net.d.ts +869 -0
  42. package/package/node_modules/@types/node/os.d.ts +466 -0
  43. package/package/node_modules/@types/node/package.json +232 -0
  44. package/package/node_modules/@types/node/path.d.ts +191 -0
  45. package/package/node_modules/@types/node/perf_hooks.d.ts +625 -0
  46. package/package/node_modules/@types/node/process.d.ts +1482 -0
  47. package/package/node_modules/@types/node/punycode.d.ts +117 -0
  48. package/package/node_modules/@types/node/querystring.d.ts +131 -0
  49. package/package/node_modules/@types/node/readline/promises.d.ts +143 -0
  50. package/package/node_modules/@types/node/readline.d.ts +653 -0
  51. package/package/node_modules/@types/node/repl.d.ts +424 -0
  52. package/package/node_modules/@types/node/stream/consumers.d.ts +12 -0
  53. package/package/node_modules/@types/node/stream/promises.d.ts +42 -0
  54. package/package/node_modules/@types/node/stream/web.d.ts +330 -0
  55. package/package/node_modules/@types/node/stream.d.ts +1340 -0
  56. package/package/node_modules/@types/node/string_decoder.d.ts +67 -0
  57. package/package/node_modules/@types/node/test.d.ts +314 -0
  58. package/package/node_modules/@types/node/timers/promises.d.ts +68 -0
  59. package/package/node_modules/@types/node/timers.d.ts +94 -0
  60. package/package/node_modules/@types/node/tls.d.ts +1028 -0
  61. package/package/node_modules/@types/node/trace_events.d.ts +171 -0
  62. package/package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  63. package/package/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
  64. package/package/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
  65. package/package/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
  66. package/package/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
  67. package/package/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
  68. package/package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
  69. package/package/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
  70. package/package/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
  71. package/package/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
  72. package/package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
  73. package/package/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
  74. package/package/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
  75. package/package/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
  76. package/package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  77. package/package/node_modules/@types/node/ts4.8/events.d.ts +678 -0
  78. package/package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
  79. package/package/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
  80. package/package/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
  81. package/package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  82. package/package/node_modules/@types/node/ts4.8/http.d.ts +1614 -0
  83. package/package/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
  84. package/package/node_modules/@types/node/ts4.8/https.d.ts +541 -0
  85. package/package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  86. package/package/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
  87. package/package/node_modules/@types/node/ts4.8/module.d.ts +114 -0
  88. package/package/node_modules/@types/node/ts4.8/net.d.ts +869 -0
  89. package/package/node_modules/@types/node/ts4.8/os.d.ts +466 -0
  90. package/package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  91. package/package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
  92. package/package/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
  93. package/package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  94. package/package/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
  95. package/package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
  96. package/package/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
  97. package/package/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
  98. package/package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  99. package/package/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
  100. package/package/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
  101. package/package/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
  102. package/package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  103. package/package/node_modules/@types/node/ts4.8/test.d.ts +314 -0
  104. package/package/node_modules/@types/node/ts4.8/timers/promises.d.ts +68 -0
  105. package/package/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
  106. package/package/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
  107. package/package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
  108. package/package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
  109. package/package/node_modules/@types/node/ts4.8/url.d.ts +897 -0
  110. package/package/node_modules/@types/node/ts4.8/util.d.ts +1850 -0
  111. package/package/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
  112. package/package/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
  113. package/package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
  114. package/package/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
  115. package/package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  116. package/package/node_modules/@types/node/tty.d.ts +206 -0
  117. package/package/node_modules/@types/node/url.d.ts +897 -0
  118. package/package/node_modules/@types/node/util.d.ts +1850 -0
  119. package/package/node_modules/@types/node/v8.d.ts +396 -0
  120. package/package/node_modules/@types/node/vm.d.ts +509 -0
  121. package/package/node_modules/@types/node/wasi.d.ts +158 -0
  122. package/package/node_modules/@types/node/worker_threads.d.ts +689 -0
  123. package/package/node_modules/@types/node/zlib.d.ts +517 -0
  124. package/package/node_modules/@types/nodemailer/LICENSE +21 -0
  125. package/package/node_modules/@types/nodemailer/README.md +16 -0
  126. package/package/node_modules/@types/nodemailer/index.d.ts +83 -0
  127. package/package/node_modules/@types/nodemailer/lib/addressparser/index.d.ts +31 -0
  128. package/package/node_modules/@types/nodemailer/lib/base64/index.d.ts +22 -0
  129. package/package/node_modules/@types/nodemailer/lib/dkim/index.d.ts +45 -0
  130. package/package/node_modules/@types/nodemailer/lib/dkim/message-parser.d.ts +75 -0
  131. package/package/node_modules/@types/nodemailer/lib/dkim/relaxed-body.d.ts +75 -0
  132. package/package/node_modules/@types/nodemailer/lib/dkim/sign.d.ts +11 -0
  133. package/package/node_modules/@types/nodemailer/lib/fetch/cookies.d.ts +54 -0
  134. package/package/node_modules/@types/nodemailer/lib/fetch/index.d.ts +38 -0
  135. package/package/node_modules/@types/nodemailer/lib/json-transport/index.d.ts +50 -0
  136. package/package/node_modules/@types/nodemailer/lib/mail-composer/index.d.ts +25 -0
  137. package/package/node_modules/@types/nodemailer/lib/mailer/index.d.ts +230 -0
  138. package/package/node_modules/@types/nodemailer/lib/mailer/mail-message.d.ts +28 -0
  139. package/package/node_modules/@types/nodemailer/lib/mime-funcs/index.d.ts +87 -0
  140. package/package/node_modules/@types/nodemailer/lib/mime-funcs/mime-types.d.ts +2 -0
  141. package/package/node_modules/@types/nodemailer/lib/mime-node/index.d.ts +137 -0
  142. package/package/node_modules/@types/nodemailer/lib/mime-node/last-newline.d.ts +9 -0
  143. package/package/node_modules/@types/nodemailer/lib/qp/index.d.ts +23 -0
  144. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/index.d.ts +53 -0
  145. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-unix.d.ts +7 -0
  146. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-windows.d.ts +7 -0
  147. package/package/node_modules/@types/nodemailer/lib/ses-transport/index.d.ts +136 -0
  148. package/package/node_modules/@types/nodemailer/lib/shared/index.d.ts +51 -0
  149. package/package/node_modules/@types/nodemailer/lib/smtp-connection/data-stream.d.ts +11 -0
  150. package/package/node_modules/@types/nodemailer/lib/smtp-connection/http-proxy-client.d.ts +11 -0
  151. package/package/node_modules/@types/nodemailer/lib/smtp-connection/index.d.ts +254 -0
  152. package/package/node_modules/@types/nodemailer/lib/smtp-pool/index.d.ts +90 -0
  153. package/package/node_modules/@types/nodemailer/lib/smtp-pool/pool-resource.d.ts +66 -0
  154. package/package/node_modules/@types/nodemailer/lib/smtp-transport/index.d.ts +115 -0
  155. package/package/node_modules/@types/nodemailer/lib/stream-transport/index.d.ts +56 -0
  156. package/package/node_modules/@types/nodemailer/lib/well-known/index.d.ts +6 -0
  157. package/package/node_modules/@types/nodemailer/lib/xoauth2/index.d.ts +110 -0
  158. package/package/node_modules/@types/nodemailer/package.json +37 -0
  159. package/package/node_modules/nodemailer/.gitattributes +6 -0
  160. package/package/node_modules/nodemailer/.prettierrc.js +8 -0
  161. package/package/node_modules/nodemailer/CHANGELOG.md +715 -0
  162. package/package/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
  163. package/package/node_modules/nodemailer/CONTRIBUTING.md +67 -0
  164. package/package/node_modules/nodemailer/LICENSE +16 -0
  165. package/package/node_modules/nodemailer/README.md +93 -0
  166. package/package/node_modules/nodemailer/SECURITY.txt +22 -0
  167. package/package/node_modules/nodemailer/lib/addressparser/index.js +313 -0
  168. package/package/node_modules/nodemailer/lib/base64/index.js +142 -0
  169. package/package/node_modules/nodemailer/lib/dkim/index.js +251 -0
  170. package/package/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
  171. package/package/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
  172. package/package/node_modules/nodemailer/lib/dkim/sign.js +117 -0
  173. package/package/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
  174. package/package/node_modules/nodemailer/lib/fetch/index.js +269 -0
  175. package/package/node_modules/nodemailer/lib/json-transport/index.js +82 -0
  176. package/package/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
  177. package/package/node_modules/nodemailer/lib/mailer/index.js +427 -0
  178. package/package/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
  179. package/package/node_modules/nodemailer/lib/mime-funcs/index.js +619 -0
  180. package/package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
  181. package/package/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
  182. package/package/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
  183. package/package/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
  184. package/package/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
  185. package/package/node_modules/nodemailer/lib/nodemailer.js +143 -0
  186. package/package/node_modules/nodemailer/lib/qp/index.js +219 -0
  187. package/package/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
  188. package/package/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
  189. package/package/node_modules/nodemailer/lib/shared/index.js +639 -0
  190. package/package/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
  191. package/package/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
  192. package/package/node_modules/nodemailer/lib/smtp-connection/index.js +1786 -0
  193. package/package/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
  194. package/package/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
  195. package/package/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
  196. package/package/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
  197. package/package/node_modules/nodemailer/lib/well-known/index.js +47 -0
  198. package/package/node_modules/nodemailer/lib/well-known/services.json +286 -0
  199. package/package/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
  200. package/package/node_modules/nodemailer/package.json +46 -0
  201. package/package/node_modules/nodemailer/postinstall.js +101 -0
  202. package/package/package-lock.json +60 -0
  203. package/package/package.json +6 -0
  204. package/package.json +19 -0
@@ -0,0 +1,1369 @@
1
+ /**
2
+ * The `child_process` module provides the ability to spawn subprocesses in
3
+ * a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability
4
+ * is primarily provided by the {@link spawn} function:
5
+ *
6
+ * ```js
7
+ * const { spawn } = require('child_process');
8
+ * const ls = spawn('ls', ['-lh', '/usr']);
9
+ *
10
+ * ls.stdout.on('data', (data) => {
11
+ * console.log(`stdout: ${data}`);
12
+ * });
13
+ *
14
+ * ls.stderr.on('data', (data) => {
15
+ * console.error(`stderr: ${data}`);
16
+ * });
17
+ *
18
+ * ls.on('close', (code) => {
19
+ * console.log(`child process exited with code ${code}`);
20
+ * });
21
+ * ```
22
+ *
23
+ * By default, pipes for `stdin`, `stdout`, and `stderr` are established between
24
+ * the parent Node.js process and the spawned subprocess. These pipes have
25
+ * limited (and platform-specific) capacity. If the subprocess writes to
26
+ * stdout in excess of that limit without the output being captured, the
27
+ * subprocess blocks waiting for the pipe buffer to accept more data. This is
28
+ * identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`option if the output will not be consumed.
29
+ *
30
+ * The command lookup is performed using the `options.env.PATH` environment
31
+ * variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is
32
+ * used. If `options.env` is set without `PATH`, lookup on Unix is performed
33
+ * on a default search path search of `/usr/bin:/bin` (see your operating system's
34
+ * manual for execvpe/execvp), on Windows the current processes environment
35
+ * variable `PATH` is used.
36
+ *
37
+ * On Windows, environment variables are case-insensitive. Node.js
38
+ * lexicographically sorts the `env` keys and uses the first one that
39
+ * case-insensitively matches. Only first (in lexicographic order) entry will be
40
+ * passed to the subprocess. This might lead to issues on Windows when passing
41
+ * objects to the `env` option that have multiple variants of the same key, such as`PATH` and `Path`.
42
+ *
43
+ * The {@link spawn} method spawns the child process asynchronously,
44
+ * without blocking the Node.js event loop. The {@link spawnSync} function provides equivalent functionality in a synchronous manner that blocks
45
+ * the event loop until the spawned process either exits or is terminated.
46
+ *
47
+ * For convenience, the `child_process` module provides a handful of synchronous
48
+ * and asynchronous alternatives to {@link spawn} and {@link spawnSync}. Each of these alternatives are implemented on
49
+ * top of {@link spawn} or {@link spawnSync}.
50
+ *
51
+ * * {@link exec}: spawns a shell and runs a command within that
52
+ * shell, passing the `stdout` and `stderr` to a callback function when
53
+ * complete.
54
+ * * {@link execFile}: similar to {@link exec} except
55
+ * that it spawns the command directly without first spawning a shell by
56
+ * default.
57
+ * * {@link fork}: spawns a new Node.js process and invokes a
58
+ * specified module with an IPC communication channel established that allows
59
+ * sending messages between parent and child.
60
+ * * {@link execSync}: a synchronous version of {@link exec} that will block the Node.js event loop.
61
+ * * {@link execFileSync}: a synchronous version of {@link execFile} that will block the Node.js event loop.
62
+ *
63
+ * For certain use cases, such as automating shell scripts, the `synchronous counterparts` may be more convenient. In many cases, however,
64
+ * the synchronous methods can have significant impact on performance due to
65
+ * stalling the event loop while spawned processes complete.
66
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/child_process.js)
67
+ */
68
+ declare module 'child_process' {
69
+ import { ObjectEncodingOptions } from 'node:fs';
70
+ import { EventEmitter, Abortable } from 'node:events';
71
+ import * as net from 'node:net';
72
+ import { Writable, Readable, Stream, Pipe } from 'node:stream';
73
+ import { URL } from 'node:url';
74
+ type Serializable = string | object | number | boolean | bigint;
75
+ type SendHandle = net.Socket | net.Server;
76
+ /**
77
+ * Instances of the `ChildProcess` represent spawned child processes.
78
+ *
79
+ * Instances of `ChildProcess` are not intended to be created directly. Rather,
80
+ * use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create
81
+ * instances of `ChildProcess`.
82
+ * @since v2.2.0
83
+ */
84
+ class ChildProcess extends EventEmitter {
85
+ /**
86
+ * A `Writable Stream` that represents the child process's `stdin`.
87
+ *
88
+ * If a child process waits to read all of its input, the child will not continue
89
+ * until this stream has been closed via `end()`.
90
+ *
91
+ * If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
92
+ * then this will be `null`.
93
+ *
94
+ * `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
95
+ * refer to the same value.
96
+ *
97
+ * The `subprocess.stdin` property can be `undefined` if the child process could
98
+ * not be successfully spawned.
99
+ * @since v0.1.90
100
+ */
101
+ stdin: Writable | null;
102
+ /**
103
+ * A `Readable Stream` that represents the child process's `stdout`.
104
+ *
105
+ * If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
106
+ * then this will be `null`.
107
+ *
108
+ * `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
109
+ * refer to the same value.
110
+ *
111
+ * ```js
112
+ * const { spawn } = require('child_process');
113
+ *
114
+ * const subprocess = spawn('ls');
115
+ *
116
+ * subprocess.stdout.on('data', (data) => {
117
+ * console.log(`Received chunk ${data}`);
118
+ * });
119
+ * ```
120
+ *
121
+ * The `subprocess.stdout` property can be `null` if the child process could
122
+ * not be successfully spawned.
123
+ * @since v0.1.90
124
+ */
125
+ stdout: Readable | null;
126
+ /**
127
+ * A `Readable Stream` that represents the child process's `stderr`.
128
+ *
129
+ * If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
130
+ * then this will be `null`.
131
+ *
132
+ * `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
133
+ * refer to the same value.
134
+ *
135
+ * The `subprocess.stderr` property can be `null` if the child process could
136
+ * not be successfully spawned.
137
+ * @since v0.1.90
138
+ */
139
+ stderr: Readable | null;
140
+ /**
141
+ * The `subprocess.channel` property is a reference to the child's IPC channel. If
142
+ * no IPC channel currently exists, this property is `undefined`.
143
+ * @since v7.1.0
144
+ */
145
+ readonly channel?: Pipe | null | undefined;
146
+ /**
147
+ * A sparse array of pipes to the child process, corresponding with positions in
148
+ * the `stdio` option passed to {@link spawn} that have been set
149
+ * to the value `'pipe'`. `subprocess.stdio[0]`, `subprocess.stdio[1]`, and`subprocess.stdio[2]` are also available as `subprocess.stdin`,`subprocess.stdout`, and `subprocess.stderr`,
150
+ * respectively.
151
+ *
152
+ * In the following example, only the child's fd `1` (stdout) is configured as a
153
+ * pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values
154
+ * in the array are `null`.
155
+ *
156
+ * ```js
157
+ * const assert = require('assert');
158
+ * const fs = require('fs');
159
+ * const child_process = require('child_process');
160
+ *
161
+ * const subprocess = child_process.spawn('ls', {
162
+ * stdio: [
163
+ * 0, // Use parent's stdin for child.
164
+ * 'pipe', // Pipe child's stdout to parent.
165
+ * fs.openSync('err.out', 'w'), // Direct child's stderr to a file.
166
+ * ]
167
+ * });
168
+ *
169
+ * assert.strictEqual(subprocess.stdio[0], null);
170
+ * assert.strictEqual(subprocess.stdio[0], subprocess.stdin);
171
+ *
172
+ * assert(subprocess.stdout);
173
+ * assert.strictEqual(subprocess.stdio[1], subprocess.stdout);
174
+ *
175
+ * assert.strictEqual(subprocess.stdio[2], null);
176
+ * assert.strictEqual(subprocess.stdio[2], subprocess.stderr);
177
+ * ```
178
+ *
179
+ * The `subprocess.stdio` property can be `undefined` if the child process could
180
+ * not be successfully spawned.
181
+ * @since v0.7.10
182
+ */
183
+ readonly stdio: [
184
+ Writable | null,
185
+ // stdin
186
+ Readable | null,
187
+ // stdout
188
+ Readable | null,
189
+ // stderr
190
+ Readable | Writable | null | undefined,
191
+ // extra
192
+ Readable | Writable | null | undefined // extra
193
+ ];
194
+ /**
195
+ * The `subprocess.killed` property indicates whether the child process
196
+ * successfully received a signal from `subprocess.kill()`. The `killed` property
197
+ * does not indicate that the child process has been terminated.
198
+ * @since v0.5.10
199
+ */
200
+ readonly killed: boolean;
201
+ /**
202
+ * Returns the process identifier (PID) of the child process. If the child process
203
+ * fails to spawn due to errors, then the value is `undefined` and `error` is
204
+ * emitted.
205
+ *
206
+ * ```js
207
+ * const { spawn } = require('child_process');
208
+ * const grep = spawn('grep', ['ssh']);
209
+ *
210
+ * console.log(`Spawned child pid: ${grep.pid}`);
211
+ * grep.stdin.end();
212
+ * ```
213
+ * @since v0.1.90
214
+ */
215
+ readonly pid?: number | undefined;
216
+ /**
217
+ * The `subprocess.connected` property indicates whether it is still possible to
218
+ * send and receive messages from a child process. When `subprocess.connected` is`false`, it is no longer possible to send or receive messages.
219
+ * @since v0.7.2
220
+ */
221
+ readonly connected: boolean;
222
+ /**
223
+ * The `subprocess.exitCode` property indicates the exit code of the child process.
224
+ * If the child process is still running, the field will be `null`.
225
+ */
226
+ readonly exitCode: number | null;
227
+ /**
228
+ * The `subprocess.signalCode` property indicates the signal received by
229
+ * the child process if any, else `null`.
230
+ */
231
+ readonly signalCode: NodeJS.Signals | null;
232
+ /**
233
+ * The `subprocess.spawnargs` property represents the full list of command-line
234
+ * arguments the child process was launched with.
235
+ */
236
+ readonly spawnargs: string[];
237
+ /**
238
+ * The `subprocess.spawnfile` property indicates the executable file name of
239
+ * the child process that is launched.
240
+ *
241
+ * For {@link fork}, its value will be equal to `process.execPath`.
242
+ * For {@link spawn}, its value will be the name of
243
+ * the executable file.
244
+ * For {@link exec}, its value will be the name of the shell
245
+ * in which the child process is launched.
246
+ */
247
+ readonly spawnfile: string;
248
+ /**
249
+ * The `subprocess.kill()` method sends a signal to the child process. If no
250
+ * argument is given, the process will be sent the `'SIGTERM'` signal. See [`signal(7)`](http://man7.org/linux/man-pages/man7/signal.7.html) for a list of available signals. This function
251
+ * returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
252
+ *
253
+ * ```js
254
+ * const { spawn } = require('child_process');
255
+ * const grep = spawn('grep', ['ssh']);
256
+ *
257
+ * grep.on('close', (code, signal) => {
258
+ * console.log(
259
+ * `child process terminated due to receipt of signal ${signal}`);
260
+ * });
261
+ *
262
+ * // Send SIGHUP to process.
263
+ * grep.kill('SIGHUP');
264
+ * ```
265
+ *
266
+ * The `ChildProcess` object may emit an `'error'` event if the signal
267
+ * cannot be delivered. Sending a signal to a child process that has already exited
268
+ * is not an error but may have unforeseen consequences. Specifically, if the
269
+ * process identifier (PID) has been reassigned to another process, the signal will
270
+ * be delivered to that process instead which can have unexpected results.
271
+ *
272
+ * While the function is called `kill`, the signal delivered to the child process
273
+ * may not actually terminate the process.
274
+ *
275
+ * See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
276
+ *
277
+ * On Windows, where POSIX signals do not exist, the `signal` argument will be
278
+ * ignored, and the process will be killed forcefully and abruptly (similar to`'SIGKILL'`).
279
+ * See `Signal Events` for more details.
280
+ *
281
+ * On Linux, child processes of child processes will not be terminated
282
+ * when attempting to kill their parent. This is likely to happen when running a
283
+ * new process in a shell or with the use of the `shell` option of `ChildProcess`:
284
+ *
285
+ * ```js
286
+ * 'use strict';
287
+ * const { spawn } = require('child_process');
288
+ *
289
+ * const subprocess = spawn(
290
+ * 'sh',
291
+ * [
292
+ * '-c',
293
+ * `node -e "setInterval(() => {
294
+ * console.log(process.pid, 'is alive')
295
+ * }, 500);"`,
296
+ * ], {
297
+ * stdio: ['inherit', 'inherit', 'inherit']
298
+ * }
299
+ * );
300
+ *
301
+ * setTimeout(() => {
302
+ * subprocess.kill(); // Does not terminate the Node.js process in the shell.
303
+ * }, 2000);
304
+ * ```
305
+ * @since v0.1.90
306
+ */
307
+ kill(signal?: NodeJS.Signals | number): boolean;
308
+ /**
309
+ * When an IPC channel has been established between the parent and child (
310
+ * i.e. when using {@link fork}), the `subprocess.send()` method can
311
+ * be used to send messages to the child process. When the child process is a
312
+ * Node.js instance, these messages can be received via the `'message'` event.
313
+ *
314
+ * The message goes through serialization and parsing. The resulting
315
+ * message might not be the same as what is originally sent.
316
+ *
317
+ * For example, in the parent script:
318
+ *
319
+ * ```js
320
+ * const cp = require('child_process');
321
+ * const n = cp.fork(`${__dirname}/sub.js`);
322
+ *
323
+ * n.on('message', (m) => {
324
+ * console.log('PARENT got message:', m);
325
+ * });
326
+ *
327
+ * // Causes the child to print: CHILD got message: { hello: 'world' }
328
+ * n.send({ hello: 'world' });
329
+ * ```
330
+ *
331
+ * And then the child script, `'sub.js'` might look like this:
332
+ *
333
+ * ```js
334
+ * process.on('message', (m) => {
335
+ * console.log('CHILD got message:', m);
336
+ * });
337
+ *
338
+ * // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
339
+ * process.send({ foo: 'bar', baz: NaN });
340
+ * ```
341
+ *
342
+ * Child Node.js processes will have a `process.send()` method of their own
343
+ * that allows the child to send messages back to the parent.
344
+ *
345
+ * There is a special case when sending a `{cmd: 'NODE_foo'}` message. Messages
346
+ * containing a `NODE_` prefix in the `cmd` property are reserved for use within
347
+ * Node.js core and will not be emitted in the child's `'message'` event. Rather, such messages are emitted using the`'internalMessage'` event and are consumed internally by Node.js.
348
+ * Applications should avoid using such messages or listening for`'internalMessage'` events as it is subject to change without notice.
349
+ *
350
+ * The optional `sendHandle` argument that may be passed to `subprocess.send()` is
351
+ * for passing a TCP server or socket object to the child process. The child will
352
+ * receive the object as the second argument passed to the callback function
353
+ * registered on the `'message'` event. Any data that is received
354
+ * and buffered in the socket will not be sent to the child.
355
+ *
356
+ * The optional `callback` is a function that is invoked after the message is
357
+ * sent but before the child may have received it. The function is called with a
358
+ * single argument: `null` on success, or an `Error` object on failure.
359
+ *
360
+ * If no `callback` function is provided and the message cannot be sent, an`'error'` event will be emitted by the `ChildProcess` object. This can
361
+ * happen, for instance, when the child process has already exited.
362
+ *
363
+ * `subprocess.send()` will return `false` if the channel has closed or when the
364
+ * backlog of unsent messages exceeds a threshold that makes it unwise to send
365
+ * more. Otherwise, the method returns `true`. The `callback` function can be
366
+ * used to implement flow control.
367
+ *
368
+ * #### Example: sending a server object
369
+ *
370
+ * The `sendHandle` argument can be used, for instance, to pass the handle of
371
+ * a TCP server object to the child process as illustrated in the example below:
372
+ *
373
+ * ```js
374
+ * const subprocess = require('child_process').fork('subprocess.js');
375
+ *
376
+ * // Open up the server object and send the handle.
377
+ * const server = require('net').createServer();
378
+ * server.on('connection', (socket) => {
379
+ * socket.end('handled by parent');
380
+ * });
381
+ * server.listen(1337, () => {
382
+ * subprocess.send('server', server);
383
+ * });
384
+ * ```
385
+ *
386
+ * The child would then receive the server object as:
387
+ *
388
+ * ```js
389
+ * process.on('message', (m, server) => {
390
+ * if (m === 'server') {
391
+ * server.on('connection', (socket) => {
392
+ * socket.end('handled by child');
393
+ * });
394
+ * }
395
+ * });
396
+ * ```
397
+ *
398
+ * Once the server is now shared between the parent and child, some connections
399
+ * can be handled by the parent and some by the child.
400
+ *
401
+ * While the example above uses a server created using the `net` module, `dgram`module servers use exactly the same workflow with the exceptions of listening on
402
+ * a `'message'` event instead of `'connection'` and using `server.bind()` instead
403
+ * of `server.listen()`. This is, however, currently only supported on Unix
404
+ * platforms.
405
+ *
406
+ * #### Example: sending a socket object
407
+ *
408
+ * Similarly, the `sendHandler` argument can be used to pass the handle of a
409
+ * socket to the child process. The example below spawns two children that each
410
+ * handle connections with "normal" or "special" priority:
411
+ *
412
+ * ```js
413
+ * const { fork } = require('child_process');
414
+ * const normal = fork('subprocess.js', ['normal']);
415
+ * const special = fork('subprocess.js', ['special']);
416
+ *
417
+ * // Open up the server and send sockets to child. Use pauseOnConnect to prevent
418
+ * // the sockets from being read before they are sent to the child process.
419
+ * const server = require('net').createServer({ pauseOnConnect: true });
420
+ * server.on('connection', (socket) => {
421
+ *
422
+ * // If this is special priority...
423
+ * if (socket.remoteAddress === '74.125.127.100') {
424
+ * special.send('socket', socket);
425
+ * return;
426
+ * }
427
+ * // This is normal priority.
428
+ * normal.send('socket', socket);
429
+ * });
430
+ * server.listen(1337);
431
+ * ```
432
+ *
433
+ * The `subprocess.js` would receive the socket handle as the second argument
434
+ * passed to the event callback function:
435
+ *
436
+ * ```js
437
+ * process.on('message', (m, socket) => {
438
+ * if (m === 'socket') {
439
+ * if (socket) {
440
+ * // Check that the client socket exists.
441
+ * // It is possible for the socket to be closed between the time it is
442
+ * // sent and the time it is received in the child process.
443
+ * socket.end(`Request handled with ${process.argv[2]} priority`);
444
+ * }
445
+ * }
446
+ * });
447
+ * ```
448
+ *
449
+ * Do not use `.maxConnections` on a socket that has been passed to a subprocess.
450
+ * The parent cannot track when the socket is destroyed.
451
+ *
452
+ * Any `'message'` handlers in the subprocess should verify that `socket` exists,
453
+ * as the connection may have been closed during the time it takes to send the
454
+ * connection to the child.
455
+ * @since v0.5.9
456
+ * @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles. `options` supports the following properties:
457
+ */
458
+ send(message: Serializable, callback?: (error: Error | null) => void): boolean;
459
+ send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
460
+ send(message: Serializable, sendHandle?: SendHandle, options?: MessageOptions, callback?: (error: Error | null) => void): boolean;
461
+ /**
462
+ * Closes the IPC channel between parent and child, allowing the child to exit
463
+ * gracefully once there are no other connections keeping it alive. After calling
464
+ * this method the `subprocess.connected` and `process.connected` properties in
465
+ * both the parent and child (respectively) will be set to `false`, and it will be
466
+ * no longer possible to pass messages between the processes.
467
+ *
468
+ * The `'disconnect'` event will be emitted when there are no messages in the
469
+ * process of being received. This will most often be triggered immediately after
470
+ * calling `subprocess.disconnect()`.
471
+ *
472
+ * When the child process is a Node.js instance (e.g. spawned using {@link fork}), the `process.disconnect()` method can be invoked
473
+ * within the child process to close the IPC channel as well.
474
+ * @since v0.7.2
475
+ */
476
+ disconnect(): void;
477
+ /**
478
+ * By default, the parent will wait for the detached child to exit. To prevent the
479
+ * parent from waiting for a given `subprocess` to exit, use the`subprocess.unref()` method. Doing so will cause the parent's event loop to not
480
+ * include the child in its reference count, allowing the parent to exit
481
+ * independently of the child, unless there is an established IPC channel between
482
+ * the child and the parent.
483
+ *
484
+ * ```js
485
+ * const { spawn } = require('child_process');
486
+ *
487
+ * const subprocess = spawn(process.argv[0], ['child_program.js'], {
488
+ * detached: true,
489
+ * stdio: 'ignore'
490
+ * });
491
+ *
492
+ * subprocess.unref();
493
+ * ```
494
+ * @since v0.7.10
495
+ */
496
+ unref(): void;
497
+ /**
498
+ * Calling `subprocess.ref()` after making a call to `subprocess.unref()` will
499
+ * restore the removed reference count for the child process, forcing the parent
500
+ * to wait for the child to exit before exiting itself.
501
+ *
502
+ * ```js
503
+ * const { spawn } = require('child_process');
504
+ *
505
+ * const subprocess = spawn(process.argv[0], ['child_program.js'], {
506
+ * detached: true,
507
+ * stdio: 'ignore'
508
+ * });
509
+ *
510
+ * subprocess.unref();
511
+ * subprocess.ref();
512
+ * ```
513
+ * @since v0.7.10
514
+ */
515
+ ref(): void;
516
+ /**
517
+ * events.EventEmitter
518
+ * 1. close
519
+ * 2. disconnect
520
+ * 3. error
521
+ * 4. exit
522
+ * 5. message
523
+ * 6. spawn
524
+ */
525
+ addListener(event: string, listener: (...args: any[]) => void): this;
526
+ addListener(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
527
+ addListener(event: 'disconnect', listener: () => void): this;
528
+ addListener(event: 'error', listener: (err: Error) => void): this;
529
+ addListener(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
530
+ addListener(event: 'message', listener: (message: Serializable, sendHandle: SendHandle) => void): this;
531
+ addListener(event: 'spawn', listener: () => void): this;
532
+ emit(event: string | symbol, ...args: any[]): boolean;
533
+ emit(event: 'close', code: number | null, signal: NodeJS.Signals | null): boolean;
534
+ emit(event: 'disconnect'): boolean;
535
+ emit(event: 'error', err: Error): boolean;
536
+ emit(event: 'exit', code: number | null, signal: NodeJS.Signals | null): boolean;
537
+ emit(event: 'message', message: Serializable, sendHandle: SendHandle): boolean;
538
+ emit(event: 'spawn', listener: () => void): boolean;
539
+ on(event: string, listener: (...args: any[]) => void): this;
540
+ on(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
541
+ on(event: 'disconnect', listener: () => void): this;
542
+ on(event: 'error', listener: (err: Error) => void): this;
543
+ on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
544
+ on(event: 'message', listener: (message: Serializable, sendHandle: SendHandle) => void): this;
545
+ on(event: 'spawn', listener: () => void): this;
546
+ once(event: string, listener: (...args: any[]) => void): this;
547
+ once(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
548
+ once(event: 'disconnect', listener: () => void): this;
549
+ once(event: 'error', listener: (err: Error) => void): this;
550
+ once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
551
+ once(event: 'message', listener: (message: Serializable, sendHandle: SendHandle) => void): this;
552
+ once(event: 'spawn', listener: () => void): this;
553
+ prependListener(event: string, listener: (...args: any[]) => void): this;
554
+ prependListener(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
555
+ prependListener(event: 'disconnect', listener: () => void): this;
556
+ prependListener(event: 'error', listener: (err: Error) => void): this;
557
+ prependListener(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
558
+ prependListener(event: 'message', listener: (message: Serializable, sendHandle: SendHandle) => void): this;
559
+ prependListener(event: 'spawn', listener: () => void): this;
560
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
561
+ prependOnceListener(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
562
+ prependOnceListener(event: 'disconnect', listener: () => void): this;
563
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
564
+ prependOnceListener(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
565
+ prependOnceListener(event: 'message', listener: (message: Serializable, sendHandle: SendHandle) => void): this;
566
+ prependOnceListener(event: 'spawn', listener: () => void): this;
567
+ }
568
+ // return this object when stdio option is undefined or not specified
569
+ interface ChildProcessWithoutNullStreams extends ChildProcess {
570
+ stdin: Writable;
571
+ stdout: Readable;
572
+ stderr: Readable;
573
+ readonly stdio: [
574
+ Writable,
575
+ Readable,
576
+ Readable,
577
+ // stderr
578
+ Readable | Writable | null | undefined,
579
+ // extra, no modification
580
+ Readable | Writable | null | undefined // extra, no modification
581
+ ];
582
+ }
583
+ // return this object when stdio option is a tuple of 3
584
+ interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable> extends ChildProcess {
585
+ stdin: I;
586
+ stdout: O;
587
+ stderr: E;
588
+ readonly stdio: [
589
+ I,
590
+ O,
591
+ E,
592
+ Readable | Writable | null | undefined,
593
+ // extra, no modification
594
+ Readable | Writable | null | undefined // extra, no modification
595
+ ];
596
+ }
597
+ interface MessageOptions {
598
+ keepOpen?: boolean | undefined;
599
+ }
600
+ type IOType = 'overlapped' | 'pipe' | 'ignore' | 'inherit';
601
+ type StdioOptions = IOType | Array<IOType | 'ipc' | Stream | number | null | undefined>;
602
+ type SerializationType = 'json' | 'advanced';
603
+ interface MessagingOptions extends Abortable {
604
+ /**
605
+ * Specify the kind of serialization used for sending messages between processes.
606
+ * @default 'json'
607
+ */
608
+ serialization?: SerializationType | undefined;
609
+ /**
610
+ * The signal value to be used when the spawned process will be killed by the abort signal.
611
+ * @default 'SIGTERM'
612
+ */
613
+ killSignal?: NodeJS.Signals | number | undefined;
614
+ /**
615
+ * In milliseconds the maximum amount of time the process is allowed to run.
616
+ */
617
+ timeout?: number | undefined;
618
+ }
619
+ interface ProcessEnvOptions {
620
+ uid?: number | undefined;
621
+ gid?: number | undefined;
622
+ cwd?: string | URL | undefined;
623
+ env?: NodeJS.ProcessEnv | undefined;
624
+ }
625
+ interface CommonOptions extends ProcessEnvOptions {
626
+ /**
627
+ * @default true
628
+ */
629
+ windowsHide?: boolean | undefined;
630
+ /**
631
+ * @default 0
632
+ */
633
+ timeout?: number | undefined;
634
+ }
635
+ interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
636
+ argv0?: string | undefined;
637
+ stdio?: StdioOptions | undefined;
638
+ shell?: boolean | string | undefined;
639
+ windowsVerbatimArguments?: boolean | undefined;
640
+ }
641
+ interface SpawnOptions extends CommonSpawnOptions {
642
+ detached?: boolean | undefined;
643
+ }
644
+ interface SpawnOptionsWithoutStdio extends SpawnOptions {
645
+ stdio?: StdioPipeNamed | StdioPipe[] | undefined;
646
+ }
647
+ type StdioNull = 'inherit' | 'ignore' | Stream;
648
+ type StdioPipeNamed = 'pipe' | 'overlapped';
649
+ type StdioPipe = undefined | null | StdioPipeNamed;
650
+ interface SpawnOptionsWithStdioTuple<Stdin extends StdioNull | StdioPipe, Stdout extends StdioNull | StdioPipe, Stderr extends StdioNull | StdioPipe> extends SpawnOptions {
651
+ stdio: [Stdin, Stdout, Stderr];
652
+ }
653
+ /**
654
+ * The `child_process.spawn()` method spawns a new process using the given`command`, with command-line arguments in `args`. If omitted, `args` defaults
655
+ * to an empty array.
656
+ *
657
+ * **If the `shell` option is enabled, do not pass unsanitized user input to this**
658
+ * **function. Any input containing shell metacharacters may be used to trigger**
659
+ * **arbitrary command execution.**
660
+ *
661
+ * A third argument may be used to specify additional options, with these defaults:
662
+ *
663
+ * ```js
664
+ * const defaults = {
665
+ * cwd: undefined,
666
+ * env: process.env
667
+ * };
668
+ * ```
669
+ *
670
+ * Use `cwd` to specify the working directory from which the process is spawned.
671
+ * If not given, the default is to inherit the current working directory. If given,
672
+ * but the path does not exist, the child process emits an `ENOENT` error
673
+ * and exits immediately. `ENOENT` is also emitted when the command
674
+ * does not exist.
675
+ *
676
+ * Use `env` to specify environment variables that will be visible to the new
677
+ * process, the default is `process.env`.
678
+ *
679
+ * `undefined` values in `env` will be ignored.
680
+ *
681
+ * Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
682
+ * exit code:
683
+ *
684
+ * ```js
685
+ * const { spawn } = require('child_process');
686
+ * const ls = spawn('ls', ['-lh', '/usr']);
687
+ *
688
+ * ls.stdout.on('data', (data) => {
689
+ * console.log(`stdout: ${data}`);
690
+ * });
691
+ *
692
+ * ls.stderr.on('data', (data) => {
693
+ * console.error(`stderr: ${data}`);
694
+ * });
695
+ *
696
+ * ls.on('close', (code) => {
697
+ * console.log(`child process exited with code ${code}`);
698
+ * });
699
+ * ```
700
+ *
701
+ * Example: A very elaborate way to run `ps ax | grep ssh`
702
+ *
703
+ * ```js
704
+ * const { spawn } = require('child_process');
705
+ * const ps = spawn('ps', ['ax']);
706
+ * const grep = spawn('grep', ['ssh']);
707
+ *
708
+ * ps.stdout.on('data', (data) => {
709
+ * grep.stdin.write(data);
710
+ * });
711
+ *
712
+ * ps.stderr.on('data', (data) => {
713
+ * console.error(`ps stderr: ${data}`);
714
+ * });
715
+ *
716
+ * ps.on('close', (code) => {
717
+ * if (code !== 0) {
718
+ * console.log(`ps process exited with code ${code}`);
719
+ * }
720
+ * grep.stdin.end();
721
+ * });
722
+ *
723
+ * grep.stdout.on('data', (data) => {
724
+ * console.log(data.toString());
725
+ * });
726
+ *
727
+ * grep.stderr.on('data', (data) => {
728
+ * console.error(`grep stderr: ${data}`);
729
+ * });
730
+ *
731
+ * grep.on('close', (code) => {
732
+ * if (code !== 0) {
733
+ * console.log(`grep process exited with code ${code}`);
734
+ * }
735
+ * });
736
+ * ```
737
+ *
738
+ * Example of checking for failed `spawn`:
739
+ *
740
+ * ```js
741
+ * const { spawn } = require('child_process');
742
+ * const subprocess = spawn('bad_command');
743
+ *
744
+ * subprocess.on('error', (err) => {
745
+ * console.error('Failed to start subprocess.');
746
+ * });
747
+ * ```
748
+ *
749
+ * Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
750
+ * title while others (Windows, SunOS) will use `command`.
751
+ *
752
+ * Node.js currently overwrites `argv[0]` with `process.execPath` on startup, so`process.argv[0]` in a Node.js child process will not match the `argv0`parameter passed to `spawn` from the parent,
753
+ * retrieve it with the`process.argv0` property instead.
754
+ *
755
+ * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
756
+ * the error passed to the callback will be an `AbortError`:
757
+ *
758
+ * ```js
759
+ * const { spawn } = require('child_process');
760
+ * const controller = new AbortController();
761
+ * const { signal } = controller;
762
+ * const grep = spawn('grep', ['ssh'], { signal });
763
+ * grep.on('error', (err) => {
764
+ * // This will be called with err being an AbortError if the controller aborts
765
+ * });
766
+ * controller.abort(); // Stops the child process
767
+ * ```
768
+ * @since v0.1.90
769
+ * @param command The command to run.
770
+ * @param args List of string arguments.
771
+ */
772
+ function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
773
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): ChildProcessByStdio<Writable, Readable, Readable>;
774
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): ChildProcessByStdio<Writable, Readable, null>;
775
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): ChildProcessByStdio<Writable, null, Readable>;
776
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): ChildProcessByStdio<null, Readable, Readable>;
777
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): ChildProcessByStdio<Writable, null, null>;
778
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): ChildProcessByStdio<null, Readable, null>;
779
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): ChildProcessByStdio<null, null, Readable>;
780
+ function spawn(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): ChildProcessByStdio<null, null, null>;
781
+ function spawn(command: string, options: SpawnOptions): ChildProcess;
782
+ // overloads of spawn with 'args'
783
+ function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
784
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): ChildProcessByStdio<Writable, Readable, Readable>;
785
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): ChildProcessByStdio<Writable, Readable, null>;
786
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): ChildProcessByStdio<Writable, null, Readable>;
787
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): ChildProcessByStdio<null, Readable, Readable>;
788
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): ChildProcessByStdio<Writable, null, null>;
789
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): ChildProcessByStdio<null, Readable, null>;
790
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): ChildProcessByStdio<null, null, Readable>;
791
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): ChildProcessByStdio<null, null, null>;
792
+ function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptions): ChildProcess;
793
+ interface ExecOptions extends CommonOptions {
794
+ shell?: string | undefined;
795
+ signal?: AbortSignal | undefined;
796
+ maxBuffer?: number | undefined;
797
+ killSignal?: NodeJS.Signals | number | undefined;
798
+ }
799
+ interface ExecOptionsWithStringEncoding extends ExecOptions {
800
+ encoding: BufferEncoding;
801
+ }
802
+ interface ExecOptionsWithBufferEncoding extends ExecOptions {
803
+ encoding: BufferEncoding | null; // specify `null`.
804
+ }
805
+ interface ExecException extends Error {
806
+ cmd?: string | undefined;
807
+ killed?: boolean | undefined;
808
+ code?: number | undefined;
809
+ signal?: NodeJS.Signals | undefined;
810
+ }
811
+ /**
812
+ * Spawns a shell then executes the `command` within that shell, buffering any
813
+ * generated output. The `command` string passed to the exec function is processed
814
+ * directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
815
+ * need to be dealt with accordingly:
816
+ *
817
+ * ```js
818
+ * const { exec } = require('child_process');
819
+ *
820
+ * exec('"/path/to/test file/test.sh" arg1 arg2');
821
+ * // Double quotes are used so that the space in the path is not interpreted as
822
+ * // a delimiter of multiple arguments.
823
+ *
824
+ * exec('echo "The \\$HOME variable is $HOME"');
825
+ * // The $HOME variable is escaped in the first instance, but not in the second.
826
+ * ```
827
+ *
828
+ * **Never pass unsanitized user input to this function. Any input containing shell**
829
+ * **metacharacters may be used to trigger arbitrary command execution.**
830
+ *
831
+ * If a `callback` function is provided, it is called with the arguments`(error, stdout, stderr)`. On success, `error` will be `null`. On error,`error` will be an instance of `Error`. The
832
+ * `error.code` property will be
833
+ * the exit code of the process. By convention, any exit code other than `0`indicates an error. `error.signal` will be the signal that terminated the
834
+ * process.
835
+ *
836
+ * The `stdout` and `stderr` arguments passed to the callback will contain the
837
+ * stdout and stderr output of the child process. By default, Node.js will decode
838
+ * the output as UTF-8 and pass strings to the callback. The `encoding` option
839
+ * can be used to specify the character encoding used to decode the stdout and
840
+ * stderr output. If `encoding` is `'buffer'`, or an unrecognized character
841
+ * encoding, `Buffer` objects will be passed to the callback instead.
842
+ *
843
+ * ```js
844
+ * const { exec } = require('child_process');
845
+ * exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
846
+ * if (error) {
847
+ * console.error(`exec error: ${error}`);
848
+ * return;
849
+ * }
850
+ * console.log(`stdout: ${stdout}`);
851
+ * console.error(`stderr: ${stderr}`);
852
+ * });
853
+ * ```
854
+ *
855
+ * If `timeout` is greater than `0`, the parent will send the signal
856
+ * identified by the `killSignal` property (the default is `'SIGTERM'`) if the
857
+ * child runs longer than `timeout` milliseconds.
858
+ *
859
+ * Unlike the [`exec(3)`](http://man7.org/linux/man-pages/man3/exec.3.html) POSIX system call, `child_process.exec()` does not replace
860
+ * the existing process and uses a shell to execute the command.
861
+ *
862
+ * If this method is invoked as its `util.promisify()` ed version, it returns
863
+ * a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
864
+ * case of an error (including any error resulting in an exit code other than 0), a
865
+ * rejected promise is returned, with the same `error` object given in the
866
+ * callback, but with two additional properties `stdout` and `stderr`.
867
+ *
868
+ * ```js
869
+ * const util = require('util');
870
+ * const exec = util.promisify(require('child_process').exec);
871
+ *
872
+ * async function lsExample() {
873
+ * const { stdout, stderr } = await exec('ls');
874
+ * console.log('stdout:', stdout);
875
+ * console.error('stderr:', stderr);
876
+ * }
877
+ * lsExample();
878
+ * ```
879
+ *
880
+ * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
881
+ * the error passed to the callback will be an `AbortError`:
882
+ *
883
+ * ```js
884
+ * const { exec } = require('child_process');
885
+ * const controller = new AbortController();
886
+ * const { signal } = controller;
887
+ * const child = exec('grep ssh', { signal }, (error) => {
888
+ * console.log(error); // an AbortError
889
+ * });
890
+ * controller.abort();
891
+ * ```
892
+ * @since v0.1.90
893
+ * @param command The command to run, with space-separated arguments.
894
+ * @param callback called with the output when process terminates.
895
+ */
896
+ function exec(command: string, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
897
+ // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
898
+ function exec(
899
+ command: string,
900
+ options: {
901
+ encoding: 'buffer' | null;
902
+ } & ExecOptions,
903
+ callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void
904
+ ): ChildProcess;
905
+ // `options` with well known `encoding` means stdout/stderr are definitely `string`.
906
+ function exec(
907
+ command: string,
908
+ options: {
909
+ encoding: BufferEncoding;
910
+ } & ExecOptions,
911
+ callback?: (error: ExecException | null, stdout: string, stderr: string) => void
912
+ ): ChildProcess;
913
+ // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
914
+ // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
915
+ function exec(
916
+ command: string,
917
+ options: {
918
+ encoding: BufferEncoding;
919
+ } & ExecOptions,
920
+ callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void
921
+ ): ChildProcess;
922
+ // `options` without an `encoding` means stdout/stderr are definitely `string`.
923
+ function exec(command: string, options: ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
924
+ // fallback if nothing else matches. Worst case is always `string | Buffer`.
925
+ function exec(
926
+ command: string,
927
+ options: (ObjectEncodingOptions & ExecOptions) | undefined | null,
928
+ callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void
929
+ ): ChildProcess;
930
+ interface PromiseWithChild<T> extends Promise<T> {
931
+ child: ChildProcess;
932
+ }
933
+ namespace exec {
934
+ function __promisify__(command: string): PromiseWithChild<{
935
+ stdout: string;
936
+ stderr: string;
937
+ }>;
938
+ function __promisify__(
939
+ command: string,
940
+ options: {
941
+ encoding: 'buffer' | null;
942
+ } & ExecOptions
943
+ ): PromiseWithChild<{
944
+ stdout: Buffer;
945
+ stderr: Buffer;
946
+ }>;
947
+ function __promisify__(
948
+ command: string,
949
+ options: {
950
+ encoding: BufferEncoding;
951
+ } & ExecOptions
952
+ ): PromiseWithChild<{
953
+ stdout: string;
954
+ stderr: string;
955
+ }>;
956
+ function __promisify__(
957
+ command: string,
958
+ options: ExecOptions
959
+ ): PromiseWithChild<{
960
+ stdout: string;
961
+ stderr: string;
962
+ }>;
963
+ function __promisify__(
964
+ command: string,
965
+ options?: (ObjectEncodingOptions & ExecOptions) | null
966
+ ): PromiseWithChild<{
967
+ stdout: string | Buffer;
968
+ stderr: string | Buffer;
969
+ }>;
970
+ }
971
+ interface ExecFileOptions extends CommonOptions, Abortable {
972
+ maxBuffer?: number | undefined;
973
+ killSignal?: NodeJS.Signals | number | undefined;
974
+ windowsVerbatimArguments?: boolean | undefined;
975
+ shell?: boolean | string | undefined;
976
+ signal?: AbortSignal | undefined;
977
+ }
978
+ interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
979
+ encoding: BufferEncoding;
980
+ }
981
+ interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
982
+ encoding: 'buffer' | null;
983
+ }
984
+ interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
985
+ encoding: BufferEncoding;
986
+ }
987
+ type ExecFileException = ExecException & NodeJS.ErrnoException;
988
+ /**
989
+ * The `child_process.execFile()` function is similar to {@link exec} except that it does not spawn a shell by default. Rather, the specified
990
+ * executable `file` is spawned directly as a new process making it slightly more
991
+ * efficient than {@link exec}.
992
+ *
993
+ * The same options as {@link exec} are supported. Since a shell is
994
+ * not spawned, behaviors such as I/O redirection and file globbing are not
995
+ * supported.
996
+ *
997
+ * ```js
998
+ * const { execFile } = require('child_process');
999
+ * const child = execFile('node', ['--version'], (error, stdout, stderr) => {
1000
+ * if (error) {
1001
+ * throw error;
1002
+ * }
1003
+ * console.log(stdout);
1004
+ * });
1005
+ * ```
1006
+ *
1007
+ * The `stdout` and `stderr` arguments passed to the callback will contain the
1008
+ * stdout and stderr output of the child process. By default, Node.js will decode
1009
+ * the output as UTF-8 and pass strings to the callback. The `encoding` option
1010
+ * can be used to specify the character encoding used to decode the stdout and
1011
+ * stderr output. If `encoding` is `'buffer'`, or an unrecognized character
1012
+ * encoding, `Buffer` objects will be passed to the callback instead.
1013
+ *
1014
+ * If this method is invoked as its `util.promisify()` ed version, it returns
1015
+ * a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
1016
+ * case of an error (including any error resulting in an exit code other than 0), a
1017
+ * rejected promise is returned, with the same `error` object given in the
1018
+ * callback, but with two additional properties `stdout` and `stderr`.
1019
+ *
1020
+ * ```js
1021
+ * const util = require('util');
1022
+ * const execFile = util.promisify(require('child_process').execFile);
1023
+ * async function getVersion() {
1024
+ * const { stdout } = await execFile('node', ['--version']);
1025
+ * console.log(stdout);
1026
+ * }
1027
+ * getVersion();
1028
+ * ```
1029
+ *
1030
+ * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1031
+ * **function. Any input containing shell metacharacters may be used to trigger**
1032
+ * **arbitrary command execution.**
1033
+ *
1034
+ * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
1035
+ * the error passed to the callback will be an `AbortError`:
1036
+ *
1037
+ * ```js
1038
+ * const { execFile } = require('child_process');
1039
+ * const controller = new AbortController();
1040
+ * const { signal } = controller;
1041
+ * const child = execFile('node', ['--version'], { signal }, (error) => {
1042
+ * console.log(error); // an AbortError
1043
+ * });
1044
+ * controller.abort();
1045
+ * ```
1046
+ * @since v0.1.91
1047
+ * @param file The name or path of the executable file to run.
1048
+ * @param args List of string arguments.
1049
+ * @param callback Called with the output when process terminates.
1050
+ */
1051
+ function execFile(file: string): ChildProcess;
1052
+ function execFile(file: string, options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
1053
+ function execFile(file: string, args?: ReadonlyArray<string> | null): ChildProcess;
1054
+ function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
1055
+ // no `options` definitely means stdout/stderr are `string`.
1056
+ function execFile(file: string, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
1057
+ function execFile(file: string, args: ReadonlyArray<string> | undefined | null, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
1058
+ // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
1059
+ function execFile(file: string, options: ExecFileOptionsWithBufferEncoding, callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
1060
+ function execFile(
1061
+ file: string,
1062
+ args: ReadonlyArray<string> | undefined | null,
1063
+ options: ExecFileOptionsWithBufferEncoding,
1064
+ callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void
1065
+ ): ChildProcess;
1066
+ // `options` with well known `encoding` means stdout/stderr are definitely `string`.
1067
+ function execFile(file: string, options: ExecFileOptionsWithStringEncoding, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
1068
+ function execFile(
1069
+ file: string,
1070
+ args: ReadonlyArray<string> | undefined | null,
1071
+ options: ExecFileOptionsWithStringEncoding,
1072
+ callback: (error: ExecFileException | null, stdout: string, stderr: string) => void
1073
+ ): ChildProcess;
1074
+ // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
1075
+ // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
1076
+ function execFile(file: string, options: ExecFileOptionsWithOtherEncoding, callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
1077
+ function execFile(
1078
+ file: string,
1079
+ args: ReadonlyArray<string> | undefined | null,
1080
+ options: ExecFileOptionsWithOtherEncoding,
1081
+ callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void
1082
+ ): ChildProcess;
1083
+ // `options` without an `encoding` means stdout/stderr are definitely `string`.
1084
+ function execFile(file: string, options: ExecFileOptions, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
1085
+ function execFile(
1086
+ file: string,
1087
+ args: ReadonlyArray<string> | undefined | null,
1088
+ options: ExecFileOptions,
1089
+ callback: (error: ExecFileException | null, stdout: string, stderr: string) => void
1090
+ ): ChildProcess;
1091
+ // fallback if nothing else matches. Worst case is always `string | Buffer`.
1092
+ function execFile(
1093
+ file: string,
1094
+ options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1095
+ callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
1096
+ ): ChildProcess;
1097
+ function execFile(
1098
+ file: string,
1099
+ args: ReadonlyArray<string> | undefined | null,
1100
+ options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
1101
+ callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
1102
+ ): ChildProcess;
1103
+ namespace execFile {
1104
+ function __promisify__(file: string): PromiseWithChild<{
1105
+ stdout: string;
1106
+ stderr: string;
1107
+ }>;
1108
+ function __promisify__(
1109
+ file: string,
1110
+ args: ReadonlyArray<string> | undefined | null
1111
+ ): PromiseWithChild<{
1112
+ stdout: string;
1113
+ stderr: string;
1114
+ }>;
1115
+ function __promisify__(
1116
+ file: string,
1117
+ options: ExecFileOptionsWithBufferEncoding
1118
+ ): PromiseWithChild<{
1119
+ stdout: Buffer;
1120
+ stderr: Buffer;
1121
+ }>;
1122
+ function __promisify__(
1123
+ file: string,
1124
+ args: ReadonlyArray<string> | undefined | null,
1125
+ options: ExecFileOptionsWithBufferEncoding
1126
+ ): PromiseWithChild<{
1127
+ stdout: Buffer;
1128
+ stderr: Buffer;
1129
+ }>;
1130
+ function __promisify__(
1131
+ file: string,
1132
+ options: ExecFileOptionsWithStringEncoding
1133
+ ): PromiseWithChild<{
1134
+ stdout: string;
1135
+ stderr: string;
1136
+ }>;
1137
+ function __promisify__(
1138
+ file: string,
1139
+ args: ReadonlyArray<string> | undefined | null,
1140
+ options: ExecFileOptionsWithStringEncoding
1141
+ ): PromiseWithChild<{
1142
+ stdout: string;
1143
+ stderr: string;
1144
+ }>;
1145
+ function __promisify__(
1146
+ file: string,
1147
+ options: ExecFileOptionsWithOtherEncoding
1148
+ ): PromiseWithChild<{
1149
+ stdout: string | Buffer;
1150
+ stderr: string | Buffer;
1151
+ }>;
1152
+ function __promisify__(
1153
+ file: string,
1154
+ args: ReadonlyArray<string> | undefined | null,
1155
+ options: ExecFileOptionsWithOtherEncoding
1156
+ ): PromiseWithChild<{
1157
+ stdout: string | Buffer;
1158
+ stderr: string | Buffer;
1159
+ }>;
1160
+ function __promisify__(
1161
+ file: string,
1162
+ options: ExecFileOptions
1163
+ ): PromiseWithChild<{
1164
+ stdout: string;
1165
+ stderr: string;
1166
+ }>;
1167
+ function __promisify__(
1168
+ file: string,
1169
+ args: ReadonlyArray<string> | undefined | null,
1170
+ options: ExecFileOptions
1171
+ ): PromiseWithChild<{
1172
+ stdout: string;
1173
+ stderr: string;
1174
+ }>;
1175
+ function __promisify__(
1176
+ file: string,
1177
+ options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null
1178
+ ): PromiseWithChild<{
1179
+ stdout: string | Buffer;
1180
+ stderr: string | Buffer;
1181
+ }>;
1182
+ function __promisify__(
1183
+ file: string,
1184
+ args: ReadonlyArray<string> | undefined | null,
1185
+ options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null
1186
+ ): PromiseWithChild<{
1187
+ stdout: string | Buffer;
1188
+ stderr: string | Buffer;
1189
+ }>;
1190
+ }
1191
+ interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
1192
+ execPath?: string | undefined;
1193
+ execArgv?: string[] | undefined;
1194
+ silent?: boolean | undefined;
1195
+ stdio?: StdioOptions | undefined;
1196
+ detached?: boolean | undefined;
1197
+ windowsVerbatimArguments?: boolean | undefined;
1198
+ }
1199
+ /**
1200
+ * The `child_process.fork()` method is a special case of {@link spawn} used specifically to spawn new Node.js processes.
1201
+ * Like {@link spawn}, a `ChildProcess` object is returned. The
1202
+ * returned `ChildProcess` will have an additional communication channel
1203
+ * built-in that allows messages to be passed back and forth between the parent and
1204
+ * child. See `subprocess.send()` for details.
1205
+ *
1206
+ * Keep in mind that spawned Node.js child processes are
1207
+ * independent of the parent with exception of the IPC communication channel
1208
+ * that is established between the two. Each process has its own memory, with
1209
+ * their own V8 instances. Because of the additional resource allocations
1210
+ * required, spawning a large number of child Node.js processes is not
1211
+ * recommended.
1212
+ *
1213
+ * By default, `child_process.fork()` will spawn new Node.js instances using the `process.execPath` of the parent process. The `execPath` property in the`options` object allows for an alternative
1214
+ * execution path to be used.
1215
+ *
1216
+ * Node.js processes launched with a custom `execPath` will communicate with the
1217
+ * parent process using the file descriptor (fd) identified using the
1218
+ * environment variable `NODE_CHANNEL_FD` on the child process.
1219
+ *
1220
+ * Unlike the [`fork(2)`](http://man7.org/linux/man-pages/man2/fork.2.html) POSIX system call, `child_process.fork()` does not clone the
1221
+ * current process.
1222
+ *
1223
+ * The `shell` option available in {@link spawn} is not supported by`child_process.fork()` and will be ignored if set.
1224
+ *
1225
+ * If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
1226
+ * the error passed to the callback will be an `AbortError`:
1227
+ *
1228
+ * ```js
1229
+ * if (process.argv[2] === 'child') {
1230
+ * setTimeout(() => {
1231
+ * console.log(`Hello from ${process.argv[2]}!`);
1232
+ * }, 1_000);
1233
+ * } else {
1234
+ * const { fork } = require('child_process');
1235
+ * const controller = new AbortController();
1236
+ * const { signal } = controller;
1237
+ * const child = fork(__filename, ['child'], { signal });
1238
+ * child.on('error', (err) => {
1239
+ * // This will be called with err being an AbortError if the controller aborts
1240
+ * });
1241
+ * controller.abort(); // Stops the child process
1242
+ * }
1243
+ * ```
1244
+ * @since v0.5.0
1245
+ * @param modulePath The module to run in the child.
1246
+ * @param args List of string arguments.
1247
+ */
1248
+ function fork(modulePath: string, options?: ForkOptions): ChildProcess;
1249
+ function fork(modulePath: string, args?: ReadonlyArray<string>, options?: ForkOptions): ChildProcess;
1250
+ interface SpawnSyncOptions extends CommonSpawnOptions {
1251
+ input?: string | NodeJS.ArrayBufferView | undefined;
1252
+ maxBuffer?: number | undefined;
1253
+ encoding?: BufferEncoding | 'buffer' | null | undefined;
1254
+ }
1255
+ interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
1256
+ encoding: BufferEncoding;
1257
+ }
1258
+ interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
1259
+ encoding?: 'buffer' | null | undefined;
1260
+ }
1261
+ interface SpawnSyncReturns<T> {
1262
+ pid: number;
1263
+ output: Array<T | null>;
1264
+ stdout: T;
1265
+ stderr: T;
1266
+ status: number | null;
1267
+ signal: NodeJS.Signals | null;
1268
+ error?: Error | undefined;
1269
+ }
1270
+ /**
1271
+ * The `child_process.spawnSync()` method is generally identical to {@link spawn} with the exception that the function will not return
1272
+ * until the child process has fully closed. When a timeout has been encountered
1273
+ * and `killSignal` is sent, the method won't return until the process has
1274
+ * completely exited. If the process intercepts and handles the `SIGTERM` signal
1275
+ * and doesn't exit, the parent process will wait until the child process has
1276
+ * exited.
1277
+ *
1278
+ * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1279
+ * **function. Any input containing shell metacharacters may be used to trigger**
1280
+ * **arbitrary command execution.**
1281
+ * @since v0.11.12
1282
+ * @param command The command to run.
1283
+ * @param args List of string arguments.
1284
+ */
1285
+ function spawnSync(command: string): SpawnSyncReturns<Buffer>;
1286
+ function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
1287
+ function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
1288
+ function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
1289
+ function spawnSync(command: string, args: ReadonlyArray<string>): SpawnSyncReturns<Buffer>;
1290
+ function spawnSync(command: string, args: ReadonlyArray<string>, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
1291
+ function spawnSync(command: string, args: ReadonlyArray<string>, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
1292
+ function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
1293
+ interface CommonExecOptions extends CommonOptions {
1294
+ input?: string | NodeJS.ArrayBufferView | undefined;
1295
+ stdio?: StdioOptions | undefined;
1296
+ killSignal?: NodeJS.Signals | number | undefined;
1297
+ maxBuffer?: number | undefined;
1298
+ encoding?: BufferEncoding | 'buffer' | null | undefined;
1299
+ }
1300
+ interface ExecSyncOptions extends CommonExecOptions {
1301
+ shell?: string | undefined;
1302
+ }
1303
+ interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
1304
+ encoding: BufferEncoding;
1305
+ }
1306
+ interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
1307
+ encoding?: 'buffer' | null | undefined;
1308
+ }
1309
+ /**
1310
+ * The `child_process.execSync()` method is generally identical to {@link exec} with the exception that the method will not return
1311
+ * until the child process has fully closed. When a timeout has been encountered
1312
+ * and `killSignal` is sent, the method won't return until the process has
1313
+ * completely exited. If the child process intercepts and handles the `SIGTERM`signal and doesn't exit, the parent process will wait until the child process
1314
+ * has exited.
1315
+ *
1316
+ * If the process times out or has a non-zero exit code, this method will throw.
1317
+ * The `Error` object will contain the entire result from {@link spawnSync}.
1318
+ *
1319
+ * **Never pass unsanitized user input to this function. Any input containing shell**
1320
+ * **metacharacters may be used to trigger arbitrary command execution.**
1321
+ * @since v0.11.12
1322
+ * @param command The command to run.
1323
+ * @return The stdout from the command.
1324
+ */
1325
+ function execSync(command: string): Buffer;
1326
+ function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
1327
+ function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer;
1328
+ function execSync(command: string, options?: ExecSyncOptions): string | Buffer;
1329
+ interface ExecFileSyncOptions extends CommonExecOptions {
1330
+ shell?: boolean | string | undefined;
1331
+ }
1332
+ interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
1333
+ encoding: BufferEncoding;
1334
+ }
1335
+ interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
1336
+ encoding?: 'buffer' | null; // specify `null`.
1337
+ }
1338
+ /**
1339
+ * The `child_process.execFileSync()` method is generally identical to {@link execFile} with the exception that the method will not
1340
+ * return until the child process has fully closed. When a timeout has been
1341
+ * encountered and `killSignal` is sent, the method won't return until the process
1342
+ * has completely exited.
1343
+ *
1344
+ * If the child process intercepts and handles the `SIGTERM` signal and
1345
+ * does not exit, the parent process will still wait until the child process has
1346
+ * exited.
1347
+ *
1348
+ * If the process times out or has a non-zero exit code, this method will throw an `Error` that will include the full result of the underlying {@link spawnSync}.
1349
+ *
1350
+ * **If the `shell` option is enabled, do not pass unsanitized user input to this**
1351
+ * **function. Any input containing shell metacharacters may be used to trigger**
1352
+ * **arbitrary command execution.**
1353
+ * @since v0.11.12
1354
+ * @param file The name or path of the executable file to run.
1355
+ * @param args List of string arguments.
1356
+ * @return The stdout from the command.
1357
+ */
1358
+ function execFileSync(file: string): Buffer;
1359
+ function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string;
1360
+ function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer;
1361
+ function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer;
1362
+ function execFileSync(file: string, args: ReadonlyArray<string>): Buffer;
1363
+ function execFileSync(file: string, args: ReadonlyArray<string>, options: ExecFileSyncOptionsWithStringEncoding): string;
1364
+ function execFileSync(file: string, args: ReadonlyArray<string>, options: ExecFileSyncOptionsWithBufferEncoding): Buffer;
1365
+ function execFileSync(file: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptions): string | Buffer;
1366
+ }
1367
+ declare module 'node:child_process' {
1368
+ export * from 'child_process';
1369
+ }