|
@ -112,6 +112,9 @@ exec('my.bat', (err, stdout, stderr) => { |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### child_process.exec(command[, options][, callback]) |
|
|
### child_process.exec(command[, options][, callback]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `command` {String} The command to run, with space-separated arguments |
|
|
* `command` {String} The command to run, with space-separated arguments |
|
|
* `options` {Object} |
|
|
* `options` {Object} |
|
@ -189,6 +192,9 @@ terminated. |
|
|
replace the existing process and uses a shell to execute the command.* |
|
|
replace the existing process and uses a shell to execute the command.* |
|
|
|
|
|
|
|
|
### child_process.execFile(file[, args][, options][, callback]) |
|
|
### child_process.execFile(file[, args][, options][, callback]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.91 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `file` {String} The name or path of the executable file to run |
|
|
* `file` {String} The name or path of the executable file to run |
|
|
* `args` {Array} List of string arguments |
|
|
* `args` {Array} List of string arguments |
|
@ -234,6 +240,9 @@ stderr output. If `encoding` is `'buffer'`, or an unrecognized character |
|
|
encoding, `Buffer` objects will be passed to the callback instead. |
|
|
encoding, `Buffer` objects will be passed to the callback instead. |
|
|
|
|
|
|
|
|
### child_process.fork(modulePath[, args][, options]) |
|
|
### child_process.fork(modulePath[, args][, options]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.5.0 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `modulePath` {String} The module to run in the child |
|
|
* `modulePath` {String} The module to run in the child |
|
|
* `args` {Array} List of string arguments |
|
|
* `args` {Array} List of string arguments |
|
@ -278,6 +287,9 @@ output on this fd is expected to be line delimited JSON objects. |
|
|
not clone the current process.* |
|
|
not clone the current process.* |
|
|
|
|
|
|
|
|
### child_process.spawn(command[, args][, options]) |
|
|
### child_process.spawn(command[, args][, options]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `command` {String} The command to run |
|
|
* `command` {String} The command to run |
|
|
* `args` {Array} List of string arguments |
|
|
* `args` {Array} List of string arguments |
|
@ -383,6 +395,9 @@ child.on('error', (err) => { |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
#### options.detached |
|
|
#### options.detached |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.10 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
On Windows, setting `options.detached` to `true` makes it possible for the |
|
|
On Windows, setting `options.detached` to `true` makes it possible for the |
|
|
child process to continue running after the parent exits. The child will have |
|
|
child process to continue running after the parent exits. The child will have |
|
@ -437,6 +452,9 @@ child.unref(); |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
#### options.stdio |
|
|
#### options.stdio |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.10 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
The `options.stdio` option is used to configure the pipes that are established |
|
|
The `options.stdio` option is used to configure the pipes that are established |
|
|
between the parent and child process. By default, the child's stdin, stdout, |
|
|
between the parent and child process. By default, the child's stdin, stdout, |
|
@ -523,6 +541,9 @@ scripting tasks and for simplifying the loading/processing of application |
|
|
configuration at startup. |
|
|
configuration at startup. |
|
|
|
|
|
|
|
|
### child_process.execFileSync(file[, args][, options]) |
|
|
### child_process.execFileSync(file[, args][, options]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.11.12 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `file` {String} The name or path of the executable file to run |
|
|
* `file` {String} The name or path of the executable file to run |
|
|
* `args` {Array} List of string arguments |
|
|
* `args` {Array} List of string arguments |
|
@ -556,6 +577,9 @@ throw. The [`Error`][] object will contain the entire result from |
|
|
[`child_process.spawnSync()`][] |
|
|
[`child_process.spawnSync()`][] |
|
|
|
|
|
|
|
|
### child_process.execSync(command[, options]) |
|
|
### child_process.execSync(command[, options]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.11.12 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `command` {String} The command to run |
|
|
* `command` {String} The command to run |
|
|
* `options` {Object} |
|
|
* `options` {Object} |
|
@ -592,6 +616,9 @@ throw. The [`Error`][] object will contain the entire result from |
|
|
[`child_process.spawnSync()`][] |
|
|
[`child_process.spawnSync()`][] |
|
|
|
|
|
|
|
|
### child_process.spawnSync(command[, args][, options]) |
|
|
### child_process.spawnSync(command[, args][, options]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.11.12 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `command` {String} The command to run |
|
|
* `command` {String} The command to run |
|
|
* `args` {Array} List of string arguments |
|
|
* `args` {Array} List of string arguments |
|
@ -626,6 +653,9 @@ completely exited. Note that if the process intercepts and handles the |
|
|
process has exited. |
|
|
process has exited. |
|
|
|
|
|
|
|
|
## Class: ChildProcess |
|
|
## Class: ChildProcess |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v2.2.0 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
Instances of the `ChildProcess` class are [`EventEmitters`][] that represent |
|
|
Instances of the `ChildProcess` class are [`EventEmitters`][] that represent |
|
|
spawned child processes. |
|
|
spawned child processes. |
|
@ -636,6 +666,9 @@ use the [`child_process.spawn()`][], [`child_process.exec()`][], |
|
|
instances of `ChildProcess`. |
|
|
instances of `ChildProcess`. |
|
|
|
|
|
|
|
|
### Event: 'close' |
|
|
### Event: 'close' |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.7 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `code` {Number} the exit code if the child exited on its own. |
|
|
* `code` {Number} the exit code if the child exited on its own. |
|
|
* `signal` {String} the signal by which the child process was terminated. |
|
|
* `signal` {String} the signal by which the child process was terminated. |
|
@ -645,6 +678,9 @@ been closed. This is distinct from the `'exit'` event, since multiple |
|
|
processes might share the same stdio streams. |
|
|
processes might share the same stdio streams. |
|
|
|
|
|
|
|
|
### Event: 'disconnect' |
|
|
### Event: 'disconnect' |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.2 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
The `'disconnect'` event is emitted after calling the |
|
|
The `'disconnect'` event is emitted after calling the |
|
|
`ChildProcess.disconnect()` method in the parent or child process. After |
|
|
`ChildProcess.disconnect()` method in the parent or child process. After |
|
@ -668,6 +704,9 @@ to guard against accidentally invoking handler functions multiple times. |
|
|
See also [`ChildProcess#kill()`][] and [`ChildProcess#send()`][]. |
|
|
See also [`ChildProcess#kill()`][] and [`ChildProcess#send()`][]. |
|
|
|
|
|
|
|
|
### Event: 'exit' |
|
|
### Event: 'exit' |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `code` {Number} the exit code if the child exited on its own. |
|
|
* `code` {Number} the exit code if the child exited on its own. |
|
|
* `signal` {String} the signal by which the child process was terminated. |
|
|
* `signal` {String} the signal by which the child process was terminated. |
|
@ -688,6 +727,9 @@ and then will re-raise the handled signal. |
|
|
See `waitpid(2)`. |
|
|
See `waitpid(2)`. |
|
|
|
|
|
|
|
|
### Event: 'message' |
|
|
### Event: 'message' |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.5.9 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `message` {Object} a parsed JSON object or primitive value. |
|
|
* `message` {Object} a parsed JSON object or primitive value. |
|
|
* `sendHandle` {Handle} a [`net.Socket`][] or [`net.Server`][] object, or |
|
|
* `sendHandle` {Handle} a [`net.Socket`][] or [`net.Server`][] object, or |
|
@ -697,6 +739,9 @@ The `'message'` event is triggered when a child process uses `process.send()` |
|
|
to send messages. |
|
|
to send messages. |
|
|
|
|
|
|
|
|
### child.connected |
|
|
### child.connected |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.2 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Boolean} Set to false after `.disconnect` is called |
|
|
* {Boolean} Set to false after `.disconnect` is called |
|
|
|
|
|
|
|
@ -705,6 +750,9 @@ and receive messages from a child process. When `child.connected` is false, it |
|
|
is no longer possible to send or receive messages. |
|
|
is no longer possible to send or receive messages. |
|
|
|
|
|
|
|
|
### child.disconnect() |
|
|
### child.disconnect() |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.2 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
Closes the IPC channel between parent and child, allowing the child to exit |
|
|
Closes the IPC channel between parent and child, allowing the child to exit |
|
|
gracefully once there are no other connections keeping it alive. After calling |
|
|
gracefully once there are no other connections keeping it alive. After calling |
|
@ -721,6 +769,9 @@ Note that when the child process is a Node.js instance (e.g. spawned using |
|
|
within the child process to close the IPC channel as well. |
|
|
within the child process to close the IPC channel as well. |
|
|
|
|
|
|
|
|
### child.kill([signal]) |
|
|
### child.kill([signal]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `signal` {String} |
|
|
* `signal` {String} |
|
|
|
|
|
|
|
@ -775,6 +826,9 @@ setTimeout(() => { |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### child.pid |
|
|
### child.pid |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Number} Integer |
|
|
* {Number} Integer |
|
|
|
|
|
|
|
@ -791,6 +845,9 @@ grep.stdin.end(); |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### child.send(message[, sendHandle][, callback]) |
|
|
### child.send(message[, sendHandle][, callback]) |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.5.9 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* `message` {Object} |
|
|
* `message` {Object} |
|
|
* `sendHandle` {Handle} |
|
|
* `sendHandle` {Handle} |
|
@ -936,6 +993,9 @@ this occurs. |
|
|
*Note: this function uses [`JSON.stringify()`][] internally to serialize the `message`.* |
|
|
*Note: this function uses [`JSON.stringify()`][] internally to serialize the `message`.* |
|
|
|
|
|
|
|
|
### child.stderr |
|
|
### child.stderr |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Stream} |
|
|
* {Stream} |
|
|
|
|
|
|
|
@ -948,6 +1008,9 @@ then this will be `undefined`. |
|
|
the same value. |
|
|
the same value. |
|
|
|
|
|
|
|
|
### child.stdin |
|
|
### child.stdin |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Stream} |
|
|
* {Stream} |
|
|
|
|
|
|
|
@ -963,6 +1026,9 @@ then this will be `undefined`. |
|
|
the same value. |
|
|
the same value. |
|
|
|
|
|
|
|
|
### child.stdio |
|
|
### child.stdio |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.7.10 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Array} |
|
|
* {Array} |
|
|
|
|
|
|
|
@ -1000,6 +1066,9 @@ assert.equal(child.stdio[2], child.stderr); |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
### child.stdout |
|
|
### child.stdout |
|
|
|
|
|
<!-- YAML |
|
|
|
|
|
added: v0.1.90 |
|
|
|
|
|
--> |
|
|
|
|
|
|
|
|
* {Stream} |
|
|
* {Stream} |
|
|
|
|
|
|
|
|