Skip to content

Commit f12c386

Browse files
jasnellMyles Borins
authored and
Myles Borins
committed
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent ce17371 commit f12c386

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

doc/api/child_process.markdown

+18-4
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ exec('my.bat', (err, stdout, stderr) => {
131131
* `gid` {Number} Sets the group identity of the process. (See setgid(2).)
132132
* `callback` {Function} called with the output when process terminates
133133
* `error` {Error}
134-
* `stdout` {Buffer}
135-
* `stderr` {Buffer}
134+
* `stdout` {String|Buffer}
135+
* `stderr` {String|Buffer}
136136
* Return: {ChildProcess}
137137

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

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

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

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

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

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

0 commit comments

Comments
 (0)