Skip to content

Commit 56755de

Browse 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

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

doc/api/child_process.markdown

Lines changed: 18 additions & 4 deletions
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)