Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d139704

Browse filesBrowse 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
Copy full SHA for d139704

File tree

Expand file treeCollapse file tree

1 file changed

+14
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-14
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.markdown‎

Copy file name to clipboardExpand all lines: doc/api/child_process.markdown
+14-14Lines changed: 14 additions & 14 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.