diff --git a/lib/child_process.js b/lib/child_process.js index 7bcd6d95f8..aadac2ed28 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -1323,10 +1323,10 @@ function checkExecSyncError(ret) { ret.error = null; if (!err) { - var cmd = ret.cmd ? ret.cmd : ret.args.join(' '); - err = new Error(util.format('Command failed: %s\n%s', - cmd, - ret.stderr.toString())); + var msg = 'Command failed: ' + + (ret.cmd ? ret.cmd : ret.args.join(' ')) + + (ret.stderr ? '\n' + ret.stderr.toString() : ''); + err = new Error(msg); } util._extend(err, ret); diff --git a/test/simple/test-child-process-execsync.js b/test/simple/test-child-process-execsync.js index 6f17ab31e7..28fa0200f2 100644 --- a/test/simple/test-child-process-execsync.js +++ b/test/simple/test-child-process-execsync.js @@ -96,3 +96,10 @@ assert.strictEqual(ret, msg + '\n', 'execFileSync encoding result should match') assert.strictEqual(response.toString().trim(), cwd); })(); + +// Verify that stderr is not accessed when stdio = 'ignore' - GH #7966 +(function() { + assert.throws(function() { + execSync('exit -1', {stdio: 'ignore'}); + }, /Command failed: exit -1/); +})();