summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRyan Sobol <contact@ryansobol.com>2015-12-31 11:14:58 -0800
committercjihrig <cjihrig@gmail.com>2016-01-13 11:24:33 -0500
commitd139704ff7742d02c624f6b60e5c416410725ae8 (patch)
tree6b4f2baf491c1eb2479bcdd1425035e4f6abeb0a /doc
parent287325c5e878e0d138f6027e9242fc6482f5a59b (diff)
downloadandroid-node-v8-d139704ff7742d02c624f6b60e5c416410725ae8.tar.gz
android-node-v8-d139704ff7742d02c624f6b60e5c416410725ae8.tar.bz2
android-node-v8-d139704ff7742d02c624f6b60e5c416410725ae8.zip
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>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/child_process.markdown28
1 files changed, 14 insertions, 14 deletions
diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown
index a210401cef..3633e6125c 100644
--- a/doc/api/child_process.markdown
+++ b/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])
-* `file` {String} The filename of the program to run
+* `file` {String} A path to an executable file
* `args` {Array} List of string arguments
* `options` {Object}
* `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}
* Return: ChildProcess object
-The `child_process.execFile()` method is similar to [`child_process.exec()`][]
-except that it does not first spawn a shell. Rather, the specified `command` 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()` and `child_process.execFile()`.
+The `child_process.execFile()` function is similar to [`child_process.exec()`][]
+except that it does not spawn a shell. Rather, the specified executable `file`
+is spawned directly as a new process making it slightly more efficient than
+[`child_process.exec()`][].
- const exec = require('child_process').execFile;
- const child = execFile('cat *.js bad_file | wc -l',
- (error, stdout, stderr) => {
- console.log(`stdout: ${stdout}`);
- console.log(`stderr: ${stderr}`);
- if (error !== null) {
- console.log(`exec error: ${error}`);
- }
+The same options as `child_process.exec()` are supported. Since a shell is not
+spawned, behaviors such as I/O redirection and file globbing are not supported.
+
+ const execFile = require('child_process').execFile;
+ const child = execFile('node', ['--version'], (error, stdout, stderr) => {
+ if (error) {
+ throw error;
+ }
+ console.log(stdout);
});
### child_process.fork(modulePath[, args][, options])