diff --git a/index.js b/index.js index d39a491c3..e2941e1e2 100644 --- a/index.js +++ b/index.js @@ -109,9 +109,10 @@ function handleInput(spawned, input) { } } -function handleOutput(options, value) { +function handleOutput(options, value, error) { if (typeof value !== 'string' && !Buffer.isBuffer(value)) { - return; + // When `execa.sync()` errors, we normalize it to '' to mimic `execa()` + return error === undefined ? undefined : ''; } if (options.stripFinalNewline) { @@ -427,8 +428,8 @@ module.exports.sync = (command, args, options) => { } const result = childProcess.spawnSync(parsed.command, parsed.args, parsed.options); - result.stdout = handleOutput(parsed.options, result.stdout); - result.stderr = handleOutput(parsed.options, result.stderr); + result.stdout = handleOutput(parsed.options, result.stdout, result.error); + result.stderr = handleOutput(parsed.options, result.stderr, result.error); if (result.error || result.status !== 0 || result.signal !== null) { const error = makeError(result, { diff --git a/readme.md b/readme.md index 15775e44a..ac1d5eb9a 100644 --- a/readme.md +++ b/readme.md @@ -107,6 +107,8 @@ try { command: 'wrong command', exitCode: 2, exitCodeName: 'ENOENT', + stdout: '', + stderr: '', failed: true, timedOut: false, isCanceled: false,