diff --git a/src/node.js b/src/node.js index af66b1784e7181..dfe35996305566 100644 --- a/src/node.js +++ b/src/node.js @@ -717,6 +717,12 @@ stdin._handle.readStop(); }); + stdin.isTTY = true; + stdin.isRaw = false; + stdin.setRawMode = function setRawMode() { + throw new Error('Not a raw device'); + }; + return stdin; }); diff --git a/test/fixtures/child-process-stdin.js b/test/fixtures/child-process-stdin.js new file mode 100644 index 00000000000000..3498949486c1c1 --- /dev/null +++ b/test/fixtures/child-process-stdin.js @@ -0,0 +1,7 @@ +console.log(process.stdin.isTTY); +console.log(process.stdin.isRaw); +try { + process.stdin.setRawMode(); +} catch (ex) { + console.error(ex); +} diff --git a/test/parallel/test-child-process-stdin.js b/test/parallel/test-child-process-stdin.js index c12b24579375dc..bc75b6b1b9a946 100644 --- a/test/parallel/test-child-process-stdin.js +++ b/test/parallel/test-child-process-stdin.js @@ -1,8 +1,9 @@ 'use strict'; var common = require('../common'); var assert = require('assert'); - +const path = require('path'); var spawn = require('child_process').spawn; +const exec = require('child_process').exec; var cat = spawn(common.isWindows ? 'more' : 'cat'); cat.stdin.write('hello'); @@ -66,3 +67,18 @@ process.on('exit', function() { assert.equal('hello world', response); } }); + +// Regression test for https://github.com/nodejs/io.js/issues/2333 +const cpFile = path.join(common.fixturesDir, 'child-process-stdin.js'); +const nodeBinary = process.argv[0]; + +exec(`${nodeBinary} ${cpFile}`, function(err, stdout, stderr) { + const stdoutLines = stdout.split('\n'); + assert.strictEqual(stdoutLines[0], 'true'); + assert.strictEqual(stdoutLines[1], 'false'); + assert.strictEqual(stdoutLines.length, 3); + + const stderrLines = stderr.split('\n'); + assert.strictEqual(stderrLines[0], '[Error: Not a raw device]'); + assert.strictEqual(stderrLines.length, 2); +});