Browse Source

doc: improve child_process.execFile() code example

PR-URL: https://github.com/nodejs/node/pull/4504
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
process-exit-stdio-flushing
Ryan Sobol 9 years ago
committed by cjihrig
parent
commit
d139704ff7
  1. 26
      doc/api/child_process.markdown

26
doc/api/child_process.markdown

@ -175,7 +175,7 @@ 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])
* `file` {String} The filename of the program to run * `file` {String} A path to an executable file
* `args` {Array} List of string arguments * `args` {Array} List of string arguments
* `options` {Object} * `options` {Object}
* `cwd` {String} Current working directory of the child process * `cwd` {String} Current working directory of the child process
@ -193,20 +193,20 @@ replace the existing process and uses a shell to execute the command.*
* `stderr` {Buffer} * `stderr` {Buffer}
* Return: ChildProcess object * Return: ChildProcess object
The `child_process.execFile()` method is similar to [`child_process.exec()`][] The `child_process.execFile()` function is similar to [`child_process.exec()`][]
except that it does not first spawn a shell. Rather, the specified `command` is except that it does not spawn a shell. Rather, the specified executable `file`
spawned directly as a new process making it slightly more efficient than is spawned directly as a new process making it slightly more efficient than
[`child_process.exec()`][]. The same options are support by both [`child_process.exec()`][].
`child_process.exec()` and `child_process.execFile()`.
const exec = require('child_process').execFile; The same options as `child_process.exec()` are supported. Since a shell is not
const child = execFile('cat *.js bad_file | wc -l', spawned, behaviors such as I/O redirection and file globbing are not supported.
(error, stdout, stderr) => {
console.log(`stdout: ${stdout}`); const execFile = require('child_process').execFile;
console.log(`stderr: ${stderr}`); const child = execFile('node', ['--version'], (error, stdout, stderr) => {
if (error !== null) { if (error) {
console.log(`exec error: ${error}`); throw error;
} }
console.log(stdout);
}); });
### child_process.fork(modulePath[, args][, options]) ### child_process.fork(modulePath[, args][, options])

Loading…
Cancel
Save