@node-red/editor-client 3.0.2 → 3.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/locales/de/editor.json +2 -0
- package/locales/de/infotips.json +0 -0
- package/locales/de/jsonata.json +0 -0
- package/locales/en-US/editor.json +37 -6
- package/locales/en-US/infotips.json +0 -0
- package/locales/en-US/jsonata.json +0 -0
- package/locales/fr/editor.json +1238 -0
- package/locales/fr/infotips.json +23 -0
- package/locales/fr/jsonata.json +274 -0
- package/locales/ja/editor.json +48 -9
- package/locales/ko/editor.json +233 -31
- package/locales/ko/infotips.json +0 -0
- package/locales/ko/jsonata.json +0 -0
- package/locales/pt-BR/editor.json +1208 -0
- package/locales/pt-BR/infotips.json +23 -0
- package/locales/pt-BR/jsonata.json +274 -0
- package/locales/ru/editor.json +2 -0
- package/locales/ru/infotips.json +0 -0
- package/locales/ru/jsonata.json +0 -0
- package/locales/zh-CN/editor.json +1175 -1049
- package/locales/zh-TW/editor.json +3 -0
- package/package.json +1 -1
- package/public/red/about +140 -0
- package/public/red/red.js +2699 -1397
- package/public/red/red.min.js +4 -3
- package/public/red/style.min.css +1 -1
- package/public/red/tours/3.0/images/context-menu.png +0 -0
- package/public/red/tours/3.0/welcome.js +155 -0
- package/public/red/tours/images/context-menu.png +0 -0
- package/public/red/tours/images/global-env-vars.png +0 -0
- package/public/red/tours/images/hiding-flows.png +0 -0
- package/public/red/tours/images/locking-flows.png +0 -0
- package/public/red/tours/images/mermaid.png +0 -0
- package/public/red/tours/images/node-help.png +0 -0
- package/public/red/tours/images/tab-changes.png +0 -0
- package/public/red/tours/welcome.js +111 -94
- package/public/types/node/assert/strict.d.ts +11 -0
- package/public/types/node/assert.d.ts +898 -64
- package/public/types/node/async_hooks.d.ts +362 -94
- package/public/types/node/buffer.d.ts +2158 -14
- package/public/types/node/child_process.d.ts +1109 -257
- package/public/types/node/cluster.d.ts +349 -200
- package/public/types/node/console.d.ts +313 -43
- package/public/types/node/crypto.d.ts +3329 -656
- package/public/types/node/dgram.d.ts +459 -58
- package/public/types/node/diagnostics_channel.d.ts +155 -0
- package/public/types/node/dns/promises.d.ts +371 -0
- package/public/types/node/dns.d.ts +532 -265
- package/public/types/node/domain.d.ts +159 -16
- package/public/types/node/events.d.ts +589 -30
- package/public/types/node/fs/promises.d.ts +1097 -0
- package/public/types/node/fs.d.ts +2484 -958
- package/public/types/node/globals.d.ts +43 -503
- package/public/types/node/http.d.ts +1156 -145
- package/public/types/node/http2.d.ts +1610 -470
- package/public/types/node/https.d.ts +462 -72
- package/public/types/node/module.d.ts +72 -13
- package/public/types/node/net.d.ts +663 -131
- package/public/types/node/os.d.ts +238 -25
- package/public/types/node/path.d.ts +57 -23
- package/public/types/node/perf_hooks.d.ts +424 -112
- package/public/types/node/process.d.ts +1261 -193
- package/public/types/node/querystring.d.ts +107 -7
- package/public/types/node/readline.d.ts +443 -74
- package/public/types/node/stream/consumers.d.ts +15 -0
- package/public/types/node/stream/promises.d.ts +45 -0
- package/public/types/node/stream/web.d.ts +395 -0
- package/public/types/node/stream.d.ts +1081 -177
- package/public/types/node/string_decoder.d.ts +57 -0
- package/public/types/node/test.d.ts +193 -0
- package/public/types/node/timers/promises.d.ts +96 -0
- package/public/types/node/timers.d.ts +87 -12
- package/public/types/node/tls.d.ts +457 -222
- package/public/types/node/trace_events.d.ts +107 -10
- package/public/types/node/tty.d.ts +158 -23
- package/public/types/node/url.d.ts +734 -28
- package/public/types/node/util.d.ts +1542 -164
- package/public/types/node/v8.d.ts +261 -73
- package/public/types/node/vm.d.ts +384 -32
- package/public/types/node/wasi.d.ts +92 -23
- package/public/types/node/worker_threads.d.ts +531 -123
- package/public/types/node/zlib.d.ts +216 -63
- package/public/types/node-red/func.d.ts +3 -0
- package/public/vendor/jquery/css/base/images/ui-icons_444444_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_555555_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777620_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_777777_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_cc0000_256x240.png +0 -0
- package/public/vendor/jquery/css/base/images/ui-icons_ffffff_256x240.png +0 -0
- package/public/vendor/jquery/css/base/jquery-ui.min.css +4 -4
- package/public/vendor/mermaid/mermaid.min.js +1284 -0
- package/public/vendor/monaco/dist/{ade705761eb7e702770d.ttf → 7064e66c3890a12c47b4.ttf} +0 -0
- package/public/vendor/monaco/dist/css.worker.js +1 -1
- package/public/vendor/monaco/dist/css.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/editor.js +1 -1
- package/public/vendor/monaco/dist/editor.js.LICENSE.txt +5 -1
- package/public/vendor/monaco/dist/editor.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js +1 -1
- package/public/vendor/monaco/dist/html.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/json.worker.js +1 -1
- package/public/vendor/monaco/dist/json.worker.js.LICENSE.txt +1 -1
- package/public/vendor/monaco/dist/locale/cs.js +319 -71
- package/public/vendor/monaco/dist/locale/de.js +323 -75
- package/public/vendor/monaco/dist/locale/es.js +318 -70
- package/public/vendor/monaco/dist/locale/fr.js +327 -79
- package/public/vendor/monaco/dist/locale/it.js +325 -77
- package/public/vendor/monaco/dist/locale/ja.js +337 -89
- package/public/vendor/monaco/dist/locale/ko.js +324 -76
- package/public/vendor/monaco/dist/locale/pl.js +322 -74
- package/public/vendor/monaco/dist/locale/pt-br.js +321 -73
- package/public/vendor/monaco/dist/locale/qps-ploc.js +1580 -1332
- package/public/vendor/monaco/dist/locale/ru.js +324 -76
- package/public/vendor/monaco/dist/locale/tr.js +326 -78
- package/public/vendor/monaco/dist/locale/zh-hans.js +328 -80
- package/public/vendor/monaco/dist/locale/zh-hant.js +321 -73
- package/public/vendor/monaco/dist/theme/forge.json +236 -0
- package/public/vendor/monaco/dist/theme/github-dark.json +348 -0
- package/public/vendor/monaco/dist/theme/github-light.json +348 -0
- package/public/vendor/monaco/dist/theme/nord.json +93 -0
- package/public/vendor/monaco/dist/ts.worker.js +1 -1
- package/public/vendor/monaco/dist/ts.worker.js.LICENSE.txt +14 -6
- package/public/vendor/vendor.js +9 -15
- /package/public/red/tours/{images → 3.0/images}/continuous-search.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/debug-path-tooltip.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-quick-add.png +0 -0
- /package/public/red/tours/{images → 3.0/images}/junction-slice.gif +0 -0
- /package/public/red/tours/{images → 3.0/images}/split-wire-with-links.gif +0 -0
|
@@ -1,42 +1,518 @@
|
|
|
1
1
|
|
|
2
2
|
/* NOTE: Do not edit directly! This file is generated using `npm run update-types` in https://github.com/Steve-Mcl/monaco-editor-esm-i18n */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The `child_process` module provides the ability to spawn subprocesses in
|
|
6
|
+
* a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability
|
|
7
|
+
* is primarily provided by the {@link spawn} function:
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* const { spawn } = require('child_process');
|
|
11
|
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
|
12
|
+
*
|
|
13
|
+
* ls.stdout.on('data', (data) => {
|
|
14
|
+
* console.log(`stdout: ${data}`);
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* ls.stderr.on('data', (data) => {
|
|
18
|
+
* console.error(`stderr: ${data}`);
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* ls.on('close', (code) => {
|
|
22
|
+
* console.log(`child process exited with code ${code}`);
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* By default, pipes for `stdin`, `stdout`, and `stderr` are established between
|
|
27
|
+
* the parent Node.js process and the spawned subprocess. These pipes have
|
|
28
|
+
* limited (and platform-specific) capacity. If the subprocess writes to
|
|
29
|
+
* stdout in excess of that limit without the output being captured, the
|
|
30
|
+
* subprocess blocks waiting for the pipe buffer to accept more data. This is
|
|
31
|
+
* identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`option if the output will not be consumed.
|
|
32
|
+
*
|
|
33
|
+
* The command lookup is performed using the `options.env.PATH` environment
|
|
34
|
+
* variable if it is in the `options` object. Otherwise, `process.env.PATH` is
|
|
35
|
+
* 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/v16.9.0/lib/child_process.js)
|
|
67
|
+
*/
|
|
4
68
|
declare module 'child_process' {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import * as net from 'net';
|
|
8
|
-
import { Writable, Readable, Stream, Pipe } from 'stream';
|
|
9
|
-
|
|
10
|
-
type Serializable = string | object | number | boolean;
|
|
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;
|
|
11
75
|
type SendHandle = net.Socket | net.Server;
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
*/
|
|
14
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
|
+
*/
|
|
15
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
|
+
*/
|
|
16
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
|
+
*/
|
|
17
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
|
+
*/
|
|
18
183
|
readonly stdio: [
|
|
19
|
-
Writable | null,
|
|
20
|
-
|
|
21
|
-
Readable | null,
|
|
22
|
-
|
|
184
|
+
Writable | null,
|
|
185
|
+
// stdin
|
|
186
|
+
Readable | null,
|
|
187
|
+
// stdout
|
|
188
|
+
Readable | null,
|
|
189
|
+
// stderr
|
|
190
|
+
Readable | Writable | null | undefined,
|
|
191
|
+
// extra
|
|
23
192
|
Readable | Writable | null | undefined // extra
|
|
24
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
|
+
*/
|
|
25
200
|
readonly killed: boolean;
|
|
26
|
-
|
|
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
|
+
*/
|
|
27
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
|
+
*/
|
|
28
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
|
+
*/
|
|
29
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
|
+
*/
|
|
30
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
|
+
*/
|
|
31
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
|
+
*/
|
|
32
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
|
+
*/
|
|
33
458
|
send(message: Serializable, callback?: (error: Error | null) => void): boolean;
|
|
34
459
|
send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
|
35
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
|
+
*/
|
|
36
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
|
+
*/
|
|
37
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
|
+
*/
|
|
38
515
|
ref(): void;
|
|
39
|
-
|
|
40
516
|
/**
|
|
41
517
|
* events.EventEmitter
|
|
42
518
|
* 1. close
|
|
@@ -44,71 +520,68 @@ declare module 'child_process' {
|
|
|
44
520
|
* 3. error
|
|
45
521
|
* 4. exit
|
|
46
522
|
* 5. message
|
|
523
|
+
* 6. spawn
|
|
47
524
|
*/
|
|
48
|
-
|
|
49
525
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
50
|
-
addListener(event:
|
|
51
|
-
addListener(event:
|
|
52
|
-
addListener(event:
|
|
53
|
-
addListener(event:
|
|
54
|
-
addListener(event:
|
|
55
|
-
|
|
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;
|
|
56
532
|
emit(event: string | symbol, ...args: any[]): boolean;
|
|
57
|
-
emit(event:
|
|
58
|
-
emit(event:
|
|
59
|
-
emit(event:
|
|
60
|
-
emit(event:
|
|
61
|
-
emit(event:
|
|
62
|
-
|
|
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;
|
|
63
539
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
64
|
-
on(event:
|
|
65
|
-
on(event:
|
|
66
|
-
on(event:
|
|
67
|
-
on(event:
|
|
68
|
-
on(event:
|
|
69
|
-
|
|
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;
|
|
70
546
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
71
|
-
once(event:
|
|
72
|
-
once(event:
|
|
73
|
-
once(event:
|
|
74
|
-
once(event:
|
|
75
|
-
once(event:
|
|
76
|
-
|
|
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;
|
|
77
553
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
78
|
-
prependListener(event:
|
|
79
|
-
prependListener(event:
|
|
80
|
-
prependListener(event:
|
|
81
|
-
prependListener(event:
|
|
82
|
-
prependListener(event:
|
|
83
|
-
|
|
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;
|
|
84
560
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
85
|
-
prependOnceListener(event:
|
|
86
|
-
prependOnceListener(event:
|
|
87
|
-
prependOnceListener(event:
|
|
88
|
-
prependOnceListener(event:
|
|
89
|
-
prependOnceListener(event:
|
|
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;
|
|
90
567
|
}
|
|
91
|
-
|
|
92
568
|
// return this object when stdio option is undefined or not specified
|
|
93
569
|
interface ChildProcessWithoutNullStreams extends ChildProcess {
|
|
94
570
|
stdin: Writable;
|
|
95
571
|
stdout: Readable;
|
|
96
572
|
stderr: Readable;
|
|
97
573
|
readonly stdio: [
|
|
98
|
-
Writable,
|
|
99
|
-
Readable,
|
|
100
|
-
Readable,
|
|
101
|
-
|
|
574
|
+
Writable,
|
|
575
|
+
Readable,
|
|
576
|
+
Readable,
|
|
577
|
+
// stderr
|
|
578
|
+
Readable | Writable | null | undefined,
|
|
579
|
+
// extra, no modification
|
|
102
580
|
Readable | Writable | null | undefined // extra, no modification
|
|
103
581
|
];
|
|
104
582
|
}
|
|
105
|
-
|
|
106
583
|
// return this object when stdio option is a tuple of 3
|
|
107
|
-
interface ChildProcessByStdio<
|
|
108
|
-
I extends null | Writable,
|
|
109
|
-
O extends null | Readable,
|
|
110
|
-
E extends null | Readable,
|
|
111
|
-
> extends ChildProcess {
|
|
584
|
+
interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable> extends ChildProcess {
|
|
112
585
|
stdin: I;
|
|
113
586
|
stdout: O;
|
|
114
587
|
stderr: E;
|
|
@@ -116,37 +589,42 @@ declare module 'child_process' {
|
|
|
116
589
|
I,
|
|
117
590
|
O,
|
|
118
591
|
E,
|
|
119
|
-
Readable | Writable | null | undefined,
|
|
592
|
+
Readable | Writable | null | undefined,
|
|
593
|
+
// extra, no modification
|
|
120
594
|
Readable | Writable | null | undefined // extra, no modification
|
|
121
595
|
];
|
|
122
596
|
}
|
|
123
|
-
|
|
124
597
|
interface MessageOptions {
|
|
125
598
|
keepOpen?: boolean | undefined;
|
|
126
599
|
}
|
|
127
|
-
|
|
128
|
-
type StdioOptions =
|
|
129
|
-
|
|
600
|
+
type IOType = 'overlapped' | 'pipe' | 'ignore' | 'inherit';
|
|
601
|
+
type StdioOptions = IOType | Array<IOType | 'ipc' | Stream | number | null | undefined>;
|
|
130
602
|
type SerializationType = 'json' | 'advanced';
|
|
131
|
-
|
|
132
|
-
interface MessagingOptions {
|
|
603
|
+
interface MessagingOptions extends Abortable {
|
|
133
604
|
/**
|
|
134
605
|
* Specify the kind of serialization used for sending messages between processes.
|
|
135
606
|
* @default 'json'
|
|
136
607
|
*/
|
|
137
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;
|
|
138
618
|
}
|
|
139
|
-
|
|
140
619
|
interface ProcessEnvOptions {
|
|
141
620
|
uid?: number | undefined;
|
|
142
621
|
gid?: number | undefined;
|
|
143
|
-
cwd?: string | undefined;
|
|
622
|
+
cwd?: string | URL | undefined;
|
|
144
623
|
env?: NodeJS.ProcessEnv | undefined;
|
|
145
624
|
}
|
|
146
|
-
|
|
147
625
|
interface CommonOptions extends ProcessEnvOptions {
|
|
148
626
|
/**
|
|
149
|
-
* @default
|
|
627
|
+
* @default false
|
|
150
628
|
*/
|
|
151
629
|
windowsHide?: boolean | undefined;
|
|
152
630
|
/**
|
|
@@ -154,183 +632,348 @@ declare module 'child_process' {
|
|
|
154
632
|
*/
|
|
155
633
|
timeout?: number | undefined;
|
|
156
634
|
}
|
|
157
|
-
|
|
158
|
-
interface CommonSpawnOptions extends CommonOptions, MessagingOptions {
|
|
635
|
+
interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
|
|
159
636
|
argv0?: string | undefined;
|
|
160
637
|
stdio?: StdioOptions | undefined;
|
|
161
638
|
shell?: boolean | string | undefined;
|
|
162
639
|
windowsVerbatimArguments?: boolean | undefined;
|
|
163
640
|
}
|
|
164
|
-
|
|
165
641
|
interface SpawnOptions extends CommonSpawnOptions {
|
|
166
642
|
detached?: boolean | undefined;
|
|
167
643
|
}
|
|
168
|
-
|
|
169
644
|
interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
|
170
|
-
stdio?:
|
|
645
|
+
stdio?: StdioPipeNamed | StdioPipe[] | undefined;
|
|
171
646
|
}
|
|
172
|
-
|
|
173
647
|
type StdioNull = 'inherit' | 'ignore' | Stream;
|
|
174
|
-
type
|
|
175
|
-
|
|
176
|
-
interface SpawnOptionsWithStdioTuple<
|
|
177
|
-
Stdin extends StdioNull | StdioPipe,
|
|
178
|
-
Stdout extends StdioNull | StdioPipe,
|
|
179
|
-
Stderr extends StdioNull | StdioPipe,
|
|
180
|
-
> extends SpawnOptions {
|
|
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 {
|
|
181
651
|
stdio: [Stdin, Stdout, Stderr];
|
|
182
652
|
}
|
|
183
|
-
|
|
184
|
-
|
|
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
|
+
*/
|
|
185
772
|
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
|
186
|
-
|
|
187
|
-
function spawn(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
): ChildProcessByStdio<Writable,
|
|
191
|
-
function spawn(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
): ChildProcessByStdio<Writable, Readable, null>;
|
|
195
|
-
function spawn(
|
|
196
|
-
command: string,
|
|
197
|
-
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
|
198
|
-
): ChildProcessByStdio<Writable, null, Readable>;
|
|
199
|
-
function spawn(
|
|
200
|
-
command: string,
|
|
201
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
|
202
|
-
): ChildProcessByStdio<null, Readable, Readable>;
|
|
203
|
-
function spawn(
|
|
204
|
-
command: string,
|
|
205
|
-
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
|
206
|
-
): ChildProcessByStdio<Writable, null, null>;
|
|
207
|
-
function spawn(
|
|
208
|
-
command: string,
|
|
209
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
|
210
|
-
): ChildProcessByStdio<null, Readable, null>;
|
|
211
|
-
function spawn(
|
|
212
|
-
command: string,
|
|
213
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
|
214
|
-
): ChildProcessByStdio<null, null, Readable>;
|
|
215
|
-
function spawn(
|
|
216
|
-
command: string,
|
|
217
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
|
218
|
-
): ChildProcessByStdio<null, null, null>;
|
|
219
|
-
|
|
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>;
|
|
220
781
|
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
|
221
|
-
|
|
222
782
|
// overloads of spawn with 'args'
|
|
223
783
|
function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
|
224
|
-
|
|
225
|
-
function spawn(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
): ChildProcessByStdio<
|
|
230
|
-
function spawn(
|
|
231
|
-
|
|
232
|
-
args: ReadonlyArray<string>,
|
|
233
|
-
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
|
234
|
-
): ChildProcessByStdio<Writable, Readable, null>;
|
|
235
|
-
function spawn(
|
|
236
|
-
command: string,
|
|
237
|
-
args: ReadonlyArray<string>,
|
|
238
|
-
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
|
239
|
-
): ChildProcessByStdio<Writable, null, Readable>;
|
|
240
|
-
function spawn(
|
|
241
|
-
command: string,
|
|
242
|
-
args: ReadonlyArray<string>,
|
|
243
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
|
244
|
-
): ChildProcessByStdio<null, Readable, Readable>;
|
|
245
|
-
function spawn(
|
|
246
|
-
command: string,
|
|
247
|
-
args: ReadonlyArray<string>,
|
|
248
|
-
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
|
249
|
-
): ChildProcessByStdio<Writable, null, null>;
|
|
250
|
-
function spawn(
|
|
251
|
-
command: string,
|
|
252
|
-
args: ReadonlyArray<string>,
|
|
253
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
|
254
|
-
): ChildProcessByStdio<null, Readable, null>;
|
|
255
|
-
function spawn(
|
|
256
|
-
command: string,
|
|
257
|
-
args: ReadonlyArray<string>,
|
|
258
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
|
259
|
-
): ChildProcessByStdio<null, null, Readable>;
|
|
260
|
-
function spawn(
|
|
261
|
-
command: string,
|
|
262
|
-
args: ReadonlyArray<string>,
|
|
263
|
-
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
|
264
|
-
): ChildProcessByStdio<null, null, null>;
|
|
265
|
-
|
|
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>;
|
|
266
792
|
function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptions): ChildProcess;
|
|
267
|
-
|
|
268
793
|
interface ExecOptions extends CommonOptions {
|
|
269
794
|
shell?: string | undefined;
|
|
795
|
+
signal?: AbortSignal | undefined;
|
|
270
796
|
maxBuffer?: number | undefined;
|
|
271
797
|
killSignal?: NodeJS.Signals | number | undefined;
|
|
272
798
|
}
|
|
273
|
-
|
|
274
799
|
interface ExecOptionsWithStringEncoding extends ExecOptions {
|
|
275
800
|
encoding: BufferEncoding;
|
|
276
801
|
}
|
|
277
|
-
|
|
278
802
|
interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
|
279
803
|
encoding: BufferEncoding | null; // specify `null`.
|
|
280
804
|
}
|
|
281
|
-
|
|
282
805
|
interface ExecException extends Error {
|
|
283
806
|
cmd?: string | undefined;
|
|
284
807
|
killed?: boolean | undefined;
|
|
285
808
|
code?: number | undefined;
|
|
286
809
|
signal?: NodeJS.Signals | undefined;
|
|
287
810
|
}
|
|
288
|
-
|
|
289
|
-
|
|
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
|
+
*/
|
|
290
896
|
function exec(command: string, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
291
|
-
|
|
292
897
|
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
|
293
|
-
function exec(
|
|
294
|
-
|
|
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;
|
|
295
905
|
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
|
296
|
-
function exec(
|
|
297
|
-
|
|
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;
|
|
298
913
|
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
|
299
914
|
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
|
300
915
|
function exec(
|
|
301
916
|
command: string,
|
|
302
|
-
options: {
|
|
303
|
-
|
|
917
|
+
options: {
|
|
918
|
+
encoding: BufferEncoding;
|
|
919
|
+
} & ExecOptions,
|
|
920
|
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void
|
|
304
921
|
): ChildProcess;
|
|
305
|
-
|
|
306
922
|
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
|
307
923
|
function exec(command: string, options: ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
308
|
-
|
|
309
924
|
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
|
310
925
|
function exec(
|
|
311
926
|
command: string,
|
|
312
|
-
options: (
|
|
313
|
-
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void
|
|
927
|
+
options: (ObjectEncodingOptions & ExecOptions) | undefined | null,
|
|
928
|
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void
|
|
314
929
|
): ChildProcess;
|
|
315
|
-
|
|
316
930
|
interface PromiseWithChild<T> extends Promise<T> {
|
|
317
931
|
child: ChildProcess;
|
|
318
932
|
}
|
|
319
|
-
|
|
320
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
321
933
|
namespace exec {
|
|
322
|
-
function __promisify__(command: string): PromiseWithChild<{
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
function __promisify__(
|
|
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
|
+
}>;
|
|
327
970
|
}
|
|
328
|
-
|
|
329
|
-
interface ExecFileOptions extends CommonOptions {
|
|
971
|
+
interface ExecFileOptions extends CommonOptions, Abortable {
|
|
330
972
|
maxBuffer?: number | undefined;
|
|
331
973
|
killSignal?: NodeJS.Signals | number | undefined;
|
|
332
974
|
windowsVerbatimArguments?: boolean | undefined;
|
|
333
975
|
shell?: boolean | string | undefined;
|
|
976
|
+
signal?: AbortSignal | undefined;
|
|
334
977
|
}
|
|
335
978
|
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
|
336
979
|
encoding: BufferEncoding;
|
|
@@ -342,48 +985,101 @@ declare module 'child_process' {
|
|
|
342
985
|
encoding: BufferEncoding;
|
|
343
986
|
}
|
|
344
987
|
type ExecFileException = ExecException & NodeJS.ErrnoException;
|
|
345
|
-
|
|
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
|
+
*/
|
|
346
1051
|
function execFile(file: string): ChildProcess;
|
|
347
|
-
function execFile(file: string, options: (
|
|
1052
|
+
function execFile(file: string, options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
|
|
348
1053
|
function execFile(file: string, args?: ReadonlyArray<string> | null): ChildProcess;
|
|
349
|
-
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: (
|
|
350
|
-
|
|
1054
|
+
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
|
|
351
1055
|
// no `options` definitely means stdout/stderr are `string`.
|
|
352
1056
|
function execFile(file: string, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
353
1057
|
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
354
|
-
|
|
355
1058
|
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
|
356
1059
|
function execFile(file: string, options: ExecFileOptionsWithBufferEncoding, callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
|
|
357
1060
|
function execFile(
|
|
358
1061
|
file: string,
|
|
359
1062
|
args: ReadonlyArray<string> | undefined | null,
|
|
360
1063
|
options: ExecFileOptionsWithBufferEncoding,
|
|
361
|
-
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void
|
|
1064
|
+
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void
|
|
362
1065
|
): ChildProcess;
|
|
363
|
-
|
|
364
1066
|
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
|
365
1067
|
function execFile(file: string, options: ExecFileOptionsWithStringEncoding, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
366
1068
|
function execFile(
|
|
367
1069
|
file: string,
|
|
368
1070
|
args: ReadonlyArray<string> | undefined | null,
|
|
369
1071
|
options: ExecFileOptionsWithStringEncoding,
|
|
370
|
-
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void
|
|
1072
|
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void
|
|
371
1073
|
): ChildProcess;
|
|
372
|
-
|
|
373
1074
|
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
|
374
1075
|
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
|
375
|
-
function execFile(
|
|
376
|
-
file: string,
|
|
377
|
-
options: ExecFileOptionsWithOtherEncoding,
|
|
378
|
-
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
|
379
|
-
): ChildProcess;
|
|
1076
|
+
function execFile(file: string, options: ExecFileOptionsWithOtherEncoding, callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
|
|
380
1077
|
function execFile(
|
|
381
1078
|
file: string,
|
|
382
1079
|
args: ReadonlyArray<string> | undefined | null,
|
|
383
1080
|
options: ExecFileOptionsWithOtherEncoding,
|
|
384
|
-
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void
|
|
1081
|
+
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void
|
|
385
1082
|
): ChildProcess;
|
|
386
|
-
|
|
387
1083
|
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
|
388
1084
|
function execFile(file: string, options: ExecFileOptions, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void): ChildProcess;
|
|
389
1085
|
function execFile(
|
|
@@ -392,45 +1088,107 @@ declare module 'child_process' {
|
|
|
392
1088
|
options: ExecFileOptions,
|
|
393
1089
|
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void
|
|
394
1090
|
): ChildProcess;
|
|
395
|
-
|
|
396
1091
|
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
|
397
1092
|
function execFile(
|
|
398
1093
|
file: string,
|
|
399
|
-
options: (
|
|
400
|
-
callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
|
|
1094
|
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
|
1095
|
+
callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
|
|
401
1096
|
): ChildProcess;
|
|
402
1097
|
function execFile(
|
|
403
1098
|
file: string,
|
|
404
1099
|
args: ReadonlyArray<string> | undefined | null,
|
|
405
|
-
options: (
|
|
406
|
-
callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
|
|
1100
|
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
|
1101
|
+
callback: ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null
|
|
407
1102
|
): ChildProcess;
|
|
408
|
-
|
|
409
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
410
1103
|
namespace execFile {
|
|
411
|
-
function __promisify__(file: string): PromiseWithChild<{
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
function __promisify__(
|
|
416
|
-
|
|
417
|
-
|
|
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
|
+
}>;
|
|
418
1152
|
function __promisify__(
|
|
419
1153
|
file: string,
|
|
420
1154
|
args: ReadonlyArray<string> | undefined | null,
|
|
421
|
-
options: ExecFileOptionsWithOtherEncoding
|
|
422
|
-
): PromiseWithChild<{
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
+
}>;
|
|
426
1167
|
function __promisify__(
|
|
427
1168
|
file: string,
|
|
428
1169
|
args: ReadonlyArray<string> | undefined | null,
|
|
429
|
-
options:
|
|
430
|
-
): PromiseWithChild<{
|
|
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
|
+
}>;
|
|
431
1190
|
}
|
|
432
|
-
|
|
433
|
-
interface ForkOptions extends ProcessEnvOptions, MessagingOptions {
|
|
1191
|
+
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
|
|
434
1192
|
execPath?: string | undefined;
|
|
435
1193
|
execArgv?: string[] | undefined;
|
|
436
1194
|
silent?: boolean | undefined;
|
|
@@ -438,12 +1196,59 @@ declare module 'child_process' {
|
|
|
438
1196
|
detached?: boolean | undefined;
|
|
439
1197
|
windowsVerbatimArguments?: boolean | undefined;
|
|
440
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
|
+
*/
|
|
441
1248
|
function fork(modulePath: string, options?: ForkOptions): ChildProcess;
|
|
442
1249
|
function fork(modulePath: string, args?: ReadonlyArray<string>, options?: ForkOptions): ChildProcess;
|
|
443
|
-
|
|
444
1250
|
interface SpawnSyncOptions extends CommonSpawnOptions {
|
|
445
1251
|
input?: string | NodeJS.ArrayBufferView | undefined;
|
|
446
|
-
killSignal?: NodeJS.Signals | number | undefined;
|
|
447
1252
|
maxBuffer?: number | undefined;
|
|
448
1253
|
encoding?: BufferEncoding | 'buffer' | null | undefined;
|
|
449
1254
|
}
|
|
@@ -462,55 +1267,102 @@ declare module 'child_process' {
|
|
|
462
1267
|
signal: NodeJS.Signals | null;
|
|
463
1268
|
error?: Error | undefined;
|
|
464
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
|
+
*/
|
|
465
1285
|
function spawnSync(command: string): SpawnSyncReturns<Buffer>;
|
|
466
|
-
function spawnSync(command: string, options
|
|
467
|
-
function spawnSync(command: string, options
|
|
1286
|
+
function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
|
1287
|
+
function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
|
468
1288
|
function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
|
|
469
|
-
function spawnSync(command: string, args
|
|
470
|
-
function spawnSync(command: string, args
|
|
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>;
|
|
471
1292
|
function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
input?: string | Uint8Array | undefined;
|
|
1293
|
+
interface CommonExecOptions extends CommonOptions {
|
|
1294
|
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
|
475
1295
|
stdio?: StdioOptions | undefined;
|
|
476
|
-
shell?: string | undefined;
|
|
477
1296
|
killSignal?: NodeJS.Signals | number | undefined;
|
|
478
1297
|
maxBuffer?: number | undefined;
|
|
479
1298
|
encoding?: BufferEncoding | 'buffer' | null | undefined;
|
|
480
1299
|
}
|
|
1300
|
+
interface ExecSyncOptions extends CommonExecOptions {
|
|
1301
|
+
shell?: string | undefined;
|
|
1302
|
+
}
|
|
481
1303
|
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
|
482
1304
|
encoding: BufferEncoding;
|
|
483
1305
|
}
|
|
484
1306
|
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
|
485
1307
|
encoding?: 'buffer' | null | undefined;
|
|
486
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
|
+
*/
|
|
487
1325
|
function execSync(command: string): Buffer;
|
|
488
1326
|
function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
|
|
489
1327
|
function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer;
|
|
490
1328
|
function execSync(command: string, options?: ExecSyncOptions): string | Buffer;
|
|
491
|
-
|
|
492
|
-
interface ExecFileSyncOptions extends CommonOptions {
|
|
493
|
-
input?: string | NodeJS.ArrayBufferView | undefined;
|
|
494
|
-
stdio?: StdioOptions | undefined;
|
|
495
|
-
killSignal?: NodeJS.Signals | number | undefined;
|
|
496
|
-
maxBuffer?: number | undefined;
|
|
497
|
-
encoding?: BufferEncoding | undefined;
|
|
1329
|
+
interface ExecFileSyncOptions extends CommonExecOptions {
|
|
498
1330
|
shell?: boolean | string | undefined;
|
|
499
1331
|
}
|
|
500
1332
|
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
|
501
1333
|
encoding: BufferEncoding;
|
|
502
1334
|
}
|
|
503
1335
|
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
|
504
|
-
encoding
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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;
|
|
514
1366
|
}
|
|
515
1367
|
declare module 'node:child_process' {
|
|
516
1368
|
export * from 'child_process';
|