Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: clarify stdout/stderr arguments to callback #6015

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions doc/api/child_process.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ exec('my.bat', (err, stdout, stderr) => {
* `gid` {Number} Sets the group identity of the process. (See setgid(2).)
* `callback` {Function} called with the output when process terminates
* `error` {Error}
* `stdout` {Buffer}
* `stderr` {Buffer}
* `stdout` {String|Buffer}
* `stderr` {String|Buffer}
* Return: {ChildProcess}

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

The `stdout` and `stderr` arguments passed to the callback will contain the
stdout and stderr output of the child process. By default, Node.js will decode
the output as UTF-8 and pass strings to the callback. The `encoding` option
can be used to specify the character encoding used to decode the stdout and
stderr output. If `encoding` is `'buffer'`, `Buffer` objects will be passed to
the callback instead.

The `options` argument may be passed as the second argument to customize how
the process is spawned. The default options are:

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

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

The `stdout` and `stderr` arguments passed to the callback will contain the
stdout and stderr output of the child process. By default, Node.js will decode
the output as UTF-8 and pass strings to the callback. The `encoding` option
can be used to specify the character encoding used to decode the stdout and
stderr output. If `encoding` is `'buffer'`, `Buffer` objects will be passed to
the callback instead.

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

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