Skip to content

Commit 9ea6082

Browse files
committed
child_process: update return types for sync methods
For the sync methods spawnSync(), execSync() and execFileSync(), when the stdio option is set to anything other than 'pipe', the stdout and stderr returned from the C++ code will be null, and not a string or Buffer as currently documented.
1 parent 641653b commit 9ea6082

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

doc/api/child_process.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,8 @@ changes:
11961196
`'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different
11971197
shell can be specified as a string. See [Shell requirements][] and
11981198
[Default Windows shell][]. **Default:** `false` (no shell).
1199-
* Returns: {Buffer|string} The stdout from the command.
1199+
* Returns: {Buffer|string|null} If `stdio` is `'pipe'`, the stdout from the
1200+
command, otherwise null.
12001201
12011202
The `child_process.execFileSync()` method is generally identical to
12021203
[`child_process.execFile()`][] with the exception that the method will not
@@ -1323,7 +1324,8 @@ changes:
13231324
**Default:** `'buffer'`.
13241325
* `windowsHide` {boolean} Hide the subprocess console window that would
13251326
normally be created on Windows systems. **Default:** `false`.
1326-
* Returns: {Buffer|string} The stdout from the command.
1327+
* Returns: {Buffer|string|null} If `stdio` is `'pipe'`, the stdout from the
1328+
command, otherwise null.
13271329
13281330
The `child_process.execSync()` method is generally identical to
13291331
[`child_process.exec()`][] with the exception that the method will not return
@@ -1407,8 +1409,10 @@ changes:
14071409
* Returns: {Object}
14081410
* `pid` {number} Pid of the child process.
14091411
* `output` {Array} Array of results from stdio output.
1410-
* `stdout` {Buffer|string} The contents of `output[1]`.
1411-
* `stderr` {Buffer|string} The contents of `output[2]`.
1412+
* `stdout` {Buffer|string|null} If `stdio` is `'pipe'`, the contents of
1413+
`output[1]`, otherwise null.
1414+
* `stderr` {Buffer|string|null} If `stdio` is `'pipe'`, the contents of
1415+
`output[2]`, otherwise null.
14121416
* `status` {number|null} The exit code of the subprocess, or `null` if the
14131417
subprocess terminated due to a signal.
14141418
* `signal` {string|null} The signal used to kill the subprocess, or `null` if

lib/child_process.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,8 @@ function spawn(file, args, options) {
823823
* @returns {{
824824
* pid: number;
825825
* output: Array;
826-
* stdout: Buffer | string;
827-
* stderr: Buffer | string;
826+
* stdout: Buffer | string | null;
827+
* stderr: Buffer | string | null;
828828
* status: number | null;
829829
* signal: string | null;
830830
* error: Error;
@@ -912,7 +912,7 @@ function checkExecSyncError(ret, args, cmd) {
912912
* windowsHide?: boolean;
913913
* shell?: boolean | string;
914914
* }} [options]
915-
* @returns {Buffer | string}
915+
* @returns {Buffer | string | null}
916916
*/
917917
function execFileSync(file, args, options) {
918918
({ file, args, options } = normalizeExecFileArgs(file, args, options));
@@ -950,7 +950,7 @@ function execFileSync(file, args, options) {
950950
* encoding?: string;
951951
* windowsHide?: boolean;
952952
* }} [options]
953-
* @returns {Buffer | string}
953+
* @returns {Buffer | string | null}
954954
*/
955955
function execSync(command, options) {
956956
const opts = normalizeExecArgs(command, options, null);

0 commit comments

Comments
 (0)