5 Node.js provides a tri-directional `popen(3)` facility through the
6 `child_process` module.
8 It is possible to stream data through a child's `stdin`, `stdout`, and
9 `stderr` in a fully non-blocking way. (Note that some programs use
10 line-buffered I/O internally. That doesn't affect Node.js but it means
11 data you send to the child process may not be immediately consumed.)
13 To create a child process, use `require('child_process').spawn()` or
14 `require('child_process').fork()`. The semantics of each are slightly
15 different as explained [below][].
17 For scripting purposes you may find the [synchronous counterparts][] more
20 ## Class: ChildProcess
22 `ChildProcess` is an [`EventEmitter`][].
24 Child processes always have three streams associated with them. `child.stdin`,
25 `child.stdout`, and `child.stderr`. These may be shared with the stdio
26 streams of the parent process, or they may be separate stream objects
27 which can be piped to and from.
29 The `ChildProcess` class is not intended to be used directly. Use the
30 [`spawn()`][], [`exec()`][], [`execFile()`][], or [`fork()`][] methods to create
31 an instance of `ChildProcess`.
35 * `code` {Number} the exit code, if it exited normally.
36 * `signal` {String} the signal passed to kill the child process, if it
37 was killed by the parent.
39 This event is emitted when the stdio streams of a child process have all
40 terminated. This is distinct from `'exit'`, since multiple processes
41 might share the same stdio streams.
43 ### Event: 'disconnect'
45 This event is emitted after calling the `.disconnect()` method in the parent
46 or in the child. After disconnecting it is no longer possible to send messages,
47 and the `.connected` property is false.
51 * `err` {Error Object} the error.
55 1. The process could not be spawned, or
56 2. The process could not be killed, or
57 3. Sending a message to the child process failed.
59 Note that the `'exit'` event may or may not fire after an error has occurred.
60 If you are listening on both events to fire a function, remember to guard
61 against calling your function twice.
63 See also [`ChildProcess#kill()`][] and [`ChildProcess#send()`][].
67 * `code` {Number} the exit code, if it exited normally.
68 * `signal` {String} the signal passed to kill the child process, if it
69 was killed by the parent.
71 This event is emitted after the child process ends. If the process terminated
72 normally, `code` is the final exit code of the process, otherwise `null`. If
73 the process terminated due to receipt of a signal, `signal` is the string name
74 of the signal, otherwise `null`.
76 Note that the child process stdio streams might still be open.
78 Also, note that Node.js establishes signal handlers for `SIGINT` and
79 `SIGTERM`. It will not terminate due to receipt of those signals. It will exit.
85 * `message` {Object} a parsed JSON object or primitive value.
86 * `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or
89 Messages sent by `.send(message, [sendHandle])` are obtained using the
94 * {Boolean} Set to false after `.disconnect` is called
96 If `.connected` is false, it is no longer possible to send messages.
98 ### child.disconnect()
100 Close the IPC channel between parent and child, allowing the child to exit
101 gracefully once there are no other connections keeping it alive. After calling
102 this method the `.connected` flag will be set to `false` in both the parent and
103 child, and it is no longer possible to send messages.
105 The `'disconnect'` event will be emitted when there are no messages in the
106 process of being received, most likely immediately.
108 Note that you can also call `process.disconnect()` in the child process when the
109 child process has any open IPC channels with the parent (i.e [`fork()`][]).
111 ### child.kill([signal])
115 Send a signal to the child process. If no argument is given, the process will
116 be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
118 const spawn = require('child_process').spawn;
119 const grep = spawn('grep', ['ssh']);
121 grep.on('close', (code, signal) => {
123 `child process terminated due to receipt of signal ${signal}`);
126 // send SIGHUP to process
129 May emit an `'error'` event when the signal cannot be delivered. Sending a
130 signal to a child process that has already exited is not an error but may
131 have unforeseen consequences. Specifically, if the process identifier (PID) has
132 been reassigned to another process, the signal will be delivered to that
133 process instead. What happens next is anyone's guess.
135 Note that while the function is called `kill`, the signal delivered to the
136 child process may not actually kill it. `kill` really just sends a signal
145 The process identifier (PID) of the child process.
149 const spawn = require('child_process').spawn;
150 const grep = spawn('grep', ['ssh']);
152 console.log(`Spawned child pid: ${grep.pid}`);
155 ### child.send(message[, sendHandle][, callback])
158 * `sendHandle` {Handle object}
159 * `callback` {Function}
162 When using [`child_process.fork()`][] you can write to the child using
163 `child.send(message[, sendHandle][, callback])` and messages are received by
164 a `'message'` event on the child.
168 const cp = require('child_process');
169 const n = cp.fork(`${__dirname}/sub.js`);
171 n.on('message', (m) => {
172 console.log('PARENT got message:', m);
175 n.send({ hello: 'world' });
177 And then the child script, `'sub.js'` might look like this:
179 process.on('message', (m) => {
180 console.log('CHILD got message:', m);
183 process.send({ foo: 'bar' });
185 In the child, the `process` object will have a `send()` method, and `process`
186 will emit objects each time it receives a message on its channel.
188 There is a special case when sending a `{cmd: 'NODE_foo'}` message. All messages
189 containing a `NODE_` prefix in its `cmd` property will not be emitted in
190 the `'message'` event, since they are internal messages used by Node.js core.
191 Messages containing the prefix are emitted in the `'internalMessage'` event.
192 Avoid using this feature; it is subject to change without notice.
194 The `sendHandle` option to `child.send()` is for sending a TCP server or
195 socket object to another process. The child will receive the object as its
196 second argument to the `'message'` event.
198 The `callback` option is a function that is invoked after the message is
199 sent but before the target may have received it. It is called with a single
200 argument: `null` on success, or an [`Error`][] object on failure.
202 `child.send()` emits an `'error'` event if no callback was given and the message
203 cannot be sent, for example because the child process has already exited.
205 Returns `true` under normal circumstances or `false` when the backlog of
206 unsent messages exceeds a threshold that makes it unwise to send more.
207 Use the callback mechanism to implement flow control.
209 #### Example: sending server object
211 Here is an example of sending a server:
213 const child = require('child_process').fork('child.js');
215 // Open up the server object and send the handle.
216 const server = require('net').createServer();
217 server.on('connection', (socket) => {
218 socket.end('handled by parent');
220 server.listen(1337, () => {
221 child.send('server', server);
224 And the child would then receive the server object as:
226 process.on('message', (m, server) => {
227 if (m === 'server') {
228 server.on('connection', (socket) => {
229 socket.end('handled by child');
234 Note that the server is now shared between the parent and child, this means
235 that some connections will be handled by the parent and some by the child.
237 For `dgram` servers the workflow is exactly the same. Here you listen on
238 a `'message'` event instead of `'connection'` and use `server.bind` instead of
239 `server.listen`. (Currently only supported on UNIX platforms.)
241 #### Example: sending socket object
243 Here is an example of sending a socket. It will spawn two children and handle
244 connections with the remote address `74.125.127.100` as VIP by sending the
245 socket to a "special" child process. Other sockets will go to a "normal"
248 const normal = require('child_process').fork('child.js', ['normal']);
249 const special = require('child_process').fork('child.js', ['special']);
251 // Open up the server and send sockets to child
252 const server = require('net').createServer();
253 server.on('connection', (socket) => {
256 if (socket.remoteAddress === '74.125.127.100') {
257 special.send('socket', socket);
261 normal.send('socket', socket);
265 The `child.js` could look like this:
267 process.on('message', (m, socket) => {
268 if (m === 'socket') {
269 socket.end(`You were handled as a ${process.argv[2]} person`);
273 Note that once a single socket has been sent to a child the parent can no
274 longer keep track of when the socket is destroyed. To indicate this condition
275 the `.connections` property becomes `null`.
276 It is also recommended not to use `.maxConnections` in this condition.
282 A `Readable Stream` that represents the child process's `stderr`.
284 If the child was not spawned with `stdio[2]` set to `'pipe'`, then this will
287 `child.stderr` is shorthand for `child.stdio[2]`. Both properties will refer
288 to the same object, or null.
294 A `Writable Stream` that represents the child process's `stdin`.
295 If the child is waiting to read all its input, it will not continue until this
296 stream has been closed via `end()`.
298 If the child was not spawned with `stdio[0]` set to `'pipe'`, then this will
301 `child.stdin` is shorthand for `child.stdio[0]`. Both properties will refer
302 to the same object, or null.
308 A sparse array of pipes to the child process, corresponding with positions in
309 the [`stdio`][] option to [`spawn()`][] that have been set to `'pipe'`.
310 Note that streams 0-2 are also available as ChildProcess.stdin,
311 ChildProcess.stdout, and ChildProcess.stderr, respectively.
313 In the following example, only the child's fd `1` is setup as a pipe, so only
314 the parent's `child.stdio[1]` is a stream, all other values in the array are
317 const assert = require('assert');
318 const fs = require('fs');
319 const child_process = require('child_process');
321 const child = child_process.spawn('ls', {
323 0, // use parents stdin for child
324 'pipe', // pipe child's stdout to parent
325 fs.openSync('err.out', 'w') // direct child's stderr to a file
329 assert.equal(child.stdio[0], null);
330 assert.equal(child.stdio[0], child.stdin);
332 assert(child.stdout);
333 assert.equal(child.stdio[1], child.stdout);
335 assert.equal(child.stdio[2], null);
336 assert.equal(child.stdio[2], child.stderr);
342 A `Readable Stream` that represents the child process's `stdout`.
344 If the child was not spawned with `stdio[1]` set to `'pipe'`, then this will
347 `child.stdout` is shorthand for `child.stdio[1]`. Both properties will refer
348 to the same object, or null.
350 ## Asynchronous Process Creation
352 These methods follow the common async programming patterns (accepting a
353 callback or returning an EventEmitter).
355 ### child_process.exec(command[, options], callback)
357 * `command` {String} The command to run, with space-separated arguments
359 * `cwd` {String} Current working directory of the child process
360 * `env` {Object} Environment key-value pairs
361 * `encoding` {String} (Default: 'utf8')
362 * `shell` {String} Shell to execute the command with
363 (Default: '/bin/sh' on UNIX, 'cmd.exe' on Windows, The shell should
364 understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows,
365 command line parsing should be compatible with `cmd.exe`.)
366 * `timeout` {Number} (Default: 0)
367 * `maxBuffer` {Number} largest amount of data (in bytes) allowed on stdout or
368 stderr - if exceeded child process is killed (Default: `200*1024`)
369 * `killSignal` {String} (Default: 'SIGTERM')
370 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
371 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
372 * `callback` {Function} called with the output when process terminates
376 * Return: ChildProcess object
378 Runs a command in a shell and buffers the output.
380 const exec = require('child_process').exec;
381 const child = exec('cat *.js bad_file | wc -l',
382 (error, stdout, stderr) => {
383 console.log(`stdout: ${stdout}`);
384 console.log(`stderr: ${stderr}`);
385 if (error !== null) {
386 console.log(`exec error: ${error}`);
390 The callback gets the arguments `(error, stdout, stderr)`. On success, `error`
391 will be `null`. On error, `error` will be an instance of [`Error`][] and `error.code`
392 will be the exit code of the child process, and `error.signal` will be set to the
393 signal that terminated the process.
395 There is a second optional argument to specify several options. The
401 killSignal: 'SIGTERM',
405 If `timeout` is greater than 0, then it will kill the child process
406 if it runs longer than `timeout` milliseconds. The child process is killed with
407 `killSignal` (default: `'SIGTERM'`). `maxBuffer` specifies the largest
408 amount of data (in bytes) allowed on stdout or stderr - if this value is
409 exceeded then the child process is killed.
411 *Note: Unlike the `exec()` POSIX system call, `child_process.exec()` does not replace
412 the existing process and uses a shell to execute the command.*
414 ### child_process.execFile(file[, args][, options][, callback])
416 * `file` {String} The filename of the program to run
417 * `args` {Array} List of string arguments
419 * `cwd` {String} Current working directory of the child process
420 * `env` {Object} Environment key-value pairs
421 * `encoding` {String} (Default: 'utf8')
422 * `timeout` {Number} (Default: 0)
423 * `maxBuffer` {Number} largest amount of data (in bytes) allowed on stdout or
424 stderr - if exceeded child process is killed (Default: 200\*1024)
425 * `killSignal` {String} (Default: 'SIGTERM')
426 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
427 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
428 * `callback` {Function} called with the output when process terminates
432 * Return: ChildProcess object
434 This is similar to [`child_process.exec()`][] except it does not execute a
435 subshell but rather the specified file directly. This makes it slightly
436 leaner than [`child_process.exec()`][]. It has the same options.
439 ### child_process.fork(modulePath[, args][, options])
441 * `modulePath` {String} The module to run in the child
442 * `args` {Array} List of string arguments
444 * `cwd` {String} Current working directory of the child process
445 * `env` {Object} Environment key-value pairs
446 * `execPath` {String} Executable used to create the child process
447 * `execArgv` {Array} List of string arguments passed to the executable
448 (Default: `process.execArgv`)
449 * `silent` {Boolean} If true, stdin, stdout, and stderr of the child will be
450 piped to the parent, otherwise they will be inherited from the parent, see
451 the `'pipe'` and `'inherit'` options for [`spawn()`][]'s [`stdio`][] for more details
453 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
454 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
455 * Return: ChildProcess object
457 This is a special case of the [`child_process.spawn()`][] functionality for
458 spawning Node.js processes. In addition to having all the methods in a normal
459 ChildProcess instance, the returned object has a communication channel built-in.
460 See [`ChildProcess#send()`][] for details.
462 These child Node.js processes are still whole new instances of V8. Assume at
463 least 30ms startup and 10mb memory for each new Node.js. That is, you cannot
464 create many thousands of them.
466 The `execPath` property in the `options` object allows for a process to be
467 created for the child rather than the current `node` executable. This should be
468 done with care and by default will talk over the fd represented an
469 environmental variable `NODE_CHANNEL_FD` on the child process. The input and
470 output on this fd is expected to be line delimited JSON objects.
472 *Note: Unlike the `fork()` POSIX system call, [`child_process.fork()`][] does not clone the
475 ### child_process.spawn(command[, args][, options])
477 * `command` {String} The command to run
478 * `args` {Array} List of string arguments
480 * `cwd` {String} Current working directory of the child process
481 * `env` {Object} Environment key-value pairs
482 * `stdio` {Array|String} Child's stdio configuration. (See
483 [below](#child_process_options_stdio))
484 * `detached` {Boolean} Prepare child to run independently of its parent
485 process. Specific behavior depends on the platform, see
486 [below](#child_process_options_detached))
487 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
488 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
489 * return: {ChildProcess object}
491 Launches a new process with the given `command`, with command line arguments in
492 `args`. If omitted, `args` defaults to an empty Array.
494 The third argument is used to specify additional options, with these defaults:
500 Use `cwd` to specify the working directory from which the process is spawned.
501 If not given, the default is to inherit the current working directory.
503 Use `env` to specify environment variables that will be visible to the new
504 process, the default is `process.env`.
506 Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit code:
508 const spawn = require('child_process').spawn;
509 const ls = spawn('ls', ['-lh', '/usr']);
511 ls.stdout.on('data', (data) => {
512 console.log(`stdout: ${data}`);
515 ls.stderr.on('data', (data) => {
516 console.log(`stderr: ${data}`);
519 ls.on('close', (code) => {
520 console.log(`child process exited with code ${code}`);
524 Example: A very elaborate way to run 'ps ax | grep ssh'
526 const spawn = require('child_process').spawn;
527 const ps = spawn('ps', ['ax']);
528 const grep = spawn('grep', ['ssh']);
530 ps.stdout.on('data', (data) => {
531 grep.stdin.write(data);
534 ps.stderr.on('data', (data) => {
535 console.log(`ps stderr: ${data}`);
538 ps.on('close', (code) => {
540 console.log(`ps process exited with code ${code}`);
545 grep.stdout.on('data', (data) => {
546 console.log(`${data}`);
549 grep.stderr.on('data', (data) => {
550 console.log(`grep stderr: ${data}`);
553 grep.on('close', (code) => {
555 console.log(`grep process exited with code ${code}`);
560 Example of checking for failed exec:
562 const spawn = require('child_process').spawn;
563 const child = spawn('bad_command');
565 child.on('error', (err) => {
566 console.log('Failed to start child process.');
569 #### options.detached
571 On Windows, this makes it possible for the child to continue running after the
572 parent exits. The child will have a new console window (this cannot be
575 On non-Windows, if the `detached` option is set, the child process will be made
576 the leader of a new process group and session. Note that child processes may
577 continue running after the parent exits whether they are detached or not. See
578 `setsid(2)` for more information.
580 By default, the parent will wait for the detached child to exit. To prevent
581 the parent from waiting for a given `child`, use the `child.unref()` method,
582 and the parent's event loop will not include the child in its reference count.
584 Example of detaching a long-running process and redirecting its output to a
587 const fs = require('fs');
588 const spawn = require('child_process').spawn;
589 const out = fs.openSync('./out.log', 'a');
590 const err = fs.openSync('./out.log', 'a');
592 const child = spawn('prg', [], {
594 stdio: [ 'ignore', out, err ]
599 When using the `detached` option to start a long-running process, the process
600 will not stay running in the background after the parent exits unless it is
601 provided with a `stdio` configuration that is not connected to the parent.
602 If the parent's `stdio` is inherited, the child will remain attached to the
603 controlling terminal.
607 As a shorthand, the `stdio` argument may be one of the following strings:
609 * `'pipe'` - `['pipe', 'pipe', 'pipe']`, this is the default value
610 * `'ignore'` - `['ignore', 'ignore', 'ignore']`
611 * `'inherit'` - `[process.stdin, process.stdout, process.stderr]` or `[0,1,2]`
613 Otherwise, the `'stdio'` option to [`child_process.spawn()`][] is an array where each
614 index corresponds to a fd in the child. The value is one of the following:
616 1. `'pipe'` - Create a pipe between the child process and the parent process.
617 The parent end of the pipe is exposed to the parent as a property on the
618 `child_process` object as `ChildProcess.stdio[fd]`. Pipes created for
619 fds 0 - 2 are also available as ChildProcess.stdin, ChildProcess.stdout
620 and ChildProcess.stderr, respectively.
621 2. `'ipc'` - Create an IPC channel for passing messages/file descriptors
622 between parent and child. A ChildProcess may have at most *one* IPC stdio
623 file descriptor. Setting this option enables the ChildProcess.send() method.
624 If the child writes JSON messages to this file descriptor, then this will
625 trigger ChildProcess.on('message'). If the child is an Node.js program, then
626 the presence of an IPC channel will enable process.send() and
627 process.on('message').
628 3. `'ignore'` - Do not set this file descriptor in the child. Note that Node.js
629 will always open fd 0 - 2 for the processes it spawns. When any of these is
630 ignored Node.js will open `/dev/null` and attach it to the child's fd.
631 4. `Stream` object - Share a readable or writable stream that refers to a tty,
632 file, socket, or a pipe with the child process. The stream's underlying
633 file descriptor is duplicated in the child process to the fd that
634 corresponds to the index in the `stdio` array. Note that the stream must
635 have an underlying descriptor (file streams do not until the `'open'`
637 5. Positive integer - The integer value is interpreted as a file descriptor
638 that is is currently open in the parent process. It is shared with the child
639 process, similar to how `Stream` objects can be shared.
640 6. `null`, `undefined` - Use default value. For stdio fds 0, 1 and 2 (in other
641 words, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the
642 default is `'ignore'`.
646 const spawn = require('child_process').spawn;
648 // Child will use parent's stdios
649 spawn('prg', [], { stdio: 'inherit' });
651 // Spawn child sharing only stderr
652 spawn('prg', [], { stdio: ['pipe', 'pipe', process.stderr] });
654 // Open an extra fd=4, to interact with programs present a
655 // startd-style interface.
656 spawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] });
658 See also: [`child_process.exec()`][] and [`child_process.fork()`][]
660 ## Synchronous Process Creation
662 These methods are **synchronous**, meaning they **WILL** block the event loop,
663 pausing execution of your code until the spawned process exits.
665 Blocking calls like these are mostly useful for simplifying general purpose
666 scripting tasks and for simplifying the loading/processing of application
667 configuration at startup.
669 ### child_process.execFileSync(file[, args][, options])
671 * `file` {String} The filename of the program to run
672 * `args` {Array} List of string arguments
674 * `cwd` {String} Current working directory of the child process
675 * `input` {String|Buffer} The value which will be passed as stdin to the spawned process
676 - supplying this value will override `stdio[0]`
677 * `stdio` {Array} Child's stdio configuration. (Default: 'pipe')
678 - `stderr` by default will be output to the parent process' stderr unless
680 * `env` {Object} Environment key-value pairs
681 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
682 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
683 * `timeout` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
684 * `killSignal` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
685 * `maxBuffer` {Number} largest amount of data (in bytes) allowed on stdout or
686 stderr - if exceeded child process is killed
687 * `encoding` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
688 * return: {Buffer|String} The stdout from the command
690 `execFileSync` will not return until the child process has fully closed. When a
691 timeout has been encountered and `killSignal` is sent, the method won't return
692 until the process has completely exited. That is to say, if the process handles
693 the `SIGTERM` signal and doesn't exit, your process will wait until the child
696 If the process times out, or has a non-zero exit code, this method ***will***
697 throw. The [`Error`][] object will contain the entire result from
698 [`child_process.spawnSync()`][]
700 ### child_process.execSync(command[, options])
702 * `command` {String} The command to run
704 * `cwd` {String} Current working directory of the child process
705 * `input` {String|Buffer} The value which will be passed as stdin to the spawned process
706 - supplying this value will override `stdio[0]`
707 * `stdio` {Array} Child's stdio configuration. (Default: 'pipe')
708 - `stderr` by default will be output to the parent process' stderr unless
710 * `env` {Object} Environment key-value pairs
711 * `shell` {String} Shell to execute the command with
712 (Default: '/bin/sh' on UNIX, 'cmd.exe' on Windows, The shell should
713 understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows,
714 command line parsing should be compatible with `cmd.exe`.)
715 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
716 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
717 * `timeout` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
718 * `killSignal` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
719 * `maxBuffer` {Number} largest amount of data (in bytes) allowed on stdout or
720 stderr - if exceeded child process is killed
721 * `encoding` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
722 * return: {Buffer|String} The stdout from the command
724 `execSync` will not return until the child process has fully closed. When a
725 timeout has been encountered and `killSignal` is sent, the method won't return
726 until the process has completely exited. That is to say, if the process handles
727 the `SIGTERM` signal and doesn't exit, your process will wait until the child
730 If the process times out, or has a non-zero exit code, this method ***will***
731 throw. The [`Error`][] object will contain the entire result from
732 [`child_process.spawnSync()`][]
734 ### child_process.spawnSync(command[, args][, options])
736 * `command` {String} The command to run
737 * `args` {Array} List of string arguments
739 * `cwd` {String} Current working directory of the child process
740 * `input` {String|Buffer} The value which will be passed as stdin to the spawned process
741 - supplying this value will override `stdio[0]`
742 * `stdio` {Array} Child's stdio configuration.
743 * `env` {Object} Environment key-value pairs
744 * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
745 * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
746 * `timeout` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
747 * `killSignal` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
748 * `maxBuffer` {Number} largest amount of data (in bytes) allowed on stdout or
749 stderr - if exceeded child process is killed
750 * `encoding` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
752 * `pid` {Number} Pid of the child process
753 * `output` {Array} Array of results from stdio output
754 * `stdout` {Buffer|String} The contents of `output[1]`
755 * `stderr` {Buffer|String} The contents of `output[2]`
756 * `status` {Number} The exit code of the child process
757 * `signal` {String} The signal used to kill the child process
758 * `error` {Error} The error object if the child process failed or timed out
760 `spawnSync` will not return until the child process has fully closed. When a
761 timeout has been encountered and `killSignal` is sent, the method won't return
762 until the process has completely exited. That is to say, if the process handles
763 the `SIGTERM` signal and doesn't exit, your process will wait until the child
766 [`child_process.exec()`]: #child_process_child_process_exec_command_options_callback
767 [`child_process.fork()`]: #child_process_child_process_fork_modulepath_args_options
768 [`child_process.spawn()`]: #child_process_child_process_spawn_command_args_options
769 [`child_process.spawnSync()`]: #child_process_child_process_spawnsync_command_args_options
770 [`ChildProcess#kill()`]: #child_process_child_kill_signal
771 [`ChildProcess#send()`]: #child_process_child_send_message_sendhandle_callback
772 [`Error`]: errors.html#errors_class_error
773 [`EventEmitter`]: events.html#events_class_events_eventemitter
774 [`exec()`]: #child_process_child_process_exec_command_options_callback
775 [`execFile()`]: #child_process_child_process_execfile_file_args_options_callback
776 [`fork()`]: #child_process_child_process_fork_modulepath_args_options
777 [`net.Server`]: net.html#net_class_net_server
778 [`net.Socket`]: net.html#net_class_net_socket
779 [`spawn()`]: #child_process_child_process_spawn_command_args_options
780 [`stdio`]: #child_process_options_stdio
781 [below]: #child_process_asynchronous_process_creation
782 [synchronous counterparts]: #child_process_synchronous_process_creation