Skip to content

Commit d139704

Browse files
ryansobolcjihrig
authored andcommitted
doc: improve child_process.execFile() code example
PR-URL: #4504 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent 287325c commit d139704

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

doc/api/child_process.markdown

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ replace the existing process and uses a shell to execute the command.*
175175

176176
### child_process.execFile(file[, args][, options][, callback])
177177

178-
* `file` {String} The filename of the program to run
178+
* `file` {String} A path to an executable file
179179
* `args` {Array} List of string arguments
180180
* `options` {Object}
181181
* `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.*
193193
* `stderr` {Buffer}
194194
* Return: ChildProcess object
195195

196-
The `child_process.execFile()` method is similar to [`child_process.exec()`][]
197-
except that it does not first spawn a shell. Rather, the specified `command` is
198-
spawned directly as a new process making it slightly more efficient than
199-
[`child_process.exec()`][]. The same options are support by both
200-
`child_process.exec()` and `child_process.execFile()`.
196+
The `child_process.execFile()` function is similar to [`child_process.exec()`][]
197+
except that it does not spawn a shell. Rather, the specified executable `file`
198+
is spawned directly as a new process making it slightly more efficient than
199+
[`child_process.exec()`][].
201200

202-
const exec = require('child_process').execFile;
203-
const child = execFile('cat *.js bad_file | wc -l',
204-
(error, stdout, stderr) => {
205-
console.log(`stdout: ${stdout}`);
206-
console.log(`stderr: ${stderr}`);
207-
if (error !== null) {
208-
console.log(`exec error: ${error}`);
209-
}
201+
The same options as `child_process.exec()` are supported. Since a shell is not
202+
spawned, behaviors such as I/O redirection and file globbing are not supported.
203+
204+
const execFile = require('child_process').execFile;
205+
const child = execFile('node', ['--version'], (error, stdout, stderr) => {
206+
if (error) {
207+
throw error;
208+
}
209+
console.log(stdout);
210210
});
211211

212212
### child_process.fork(modulePath[, args][, options])

0 commit comments

Comments
 (0)