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 56755de

Browse filesBrowse files
jasnellMyles Borins
authored andcommitted
doc: clarify stdout/stderr arguments to callback
Clarify that the arguments to child_process.execFile and child_process.exec callback can be Buffer or strings. Fixes: #3389 PR-URL: #6015 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 73e3b7b commit 56755de
Copy full SHA for 56755de

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+18
-4
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
+18-4Lines changed: 18 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ exec('my.bat', (err, stdout, stderr) => {
130130
* `gid` {Number} Sets the group identity of the process. (See setgid(2).)
131131
* `callback` {Function} called with the output when process terminates
132132
* `error` {Error}
133-
* `stdout` {Buffer}
134-
* `stderr` {Buffer}
133+
* `stdout` {String|Buffer}
134+
* `stderr` {String|Buffer}
135135
* Return: {ChildProcess}
136136

137137
Spawns a shell then executes the `command` within that shell, buffering any
@@ -156,6 +156,13 @@ the exit code of the child process while `error.signal` will be set to the
156156
signal that terminated the process. Any exit code other than `0` is considered
157157
to be an error.
158158

159+
The `stdout` and `stderr` arguments passed to the callback will contain the
160+
stdout and stderr output of the child process. By default, Node.js will decode
161+
the output as UTF-8 and pass strings to the callback. The `encoding` option
162+
can be used to specify the character encoding used to decode the stdout and
163+
stderr output. If `encoding` is `'buffer'`, `Buffer` objects will be passed to
164+
the callback instead.
165+
159166
The `options` argument may be passed as the second argument to customize how
160167
the process is spawned. The default options are:
161168

@@ -197,8 +204,8 @@ replace the existing process and uses a shell to execute the command.*
197204
* `gid` {Number} Sets the group identity of the process. (See setgid(2).)
198205
* `callback` {Function} called with the output when process terminates
199206
* `error` {Error}
200-
* `stdout` {Buffer}
201-
* `stderr` {Buffer}
207+
* `stdout` {String|Buffer}
208+
* `stderr` {String|Buffer}
202209
* Return: {ChildProcess}
203210

204211
The `child_process.execFile()` function is similar to [`child_process.exec()`][]
@@ -219,6 +226,13 @@ const child = execFile('node', ['--version'], (error, stdout, stderr) => {
219226
});
220227
```
221228

229+
The `stdout` and `stderr` arguments passed to the callback will contain the
230+
stdout and stderr output of the child process. By default, Node.js will decode
231+
the output as UTF-8 and pass strings to the callback. The `encoding` option
232+
can be used to specify the character encoding used to decode the stdout and
233+
stderr output. If `encoding` is `'buffer'`, `Buffer` objects will be passed to
234+
the callback instead.
235+
222236
### child_process.fork(modulePath[, args][, options])
223237

224238
* `modulePath` {String} The module to run in the child

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.