diff --git a/lib/child_process.js b/lib/child_process.js index 1fecbc7557..f69c47d390 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -696,12 +696,33 @@ function ChildProcess() { self.emit('exit', self.exitCode, self.signalCode); } + // if any of the stdio streams have not been touched, + // then pull all the data through so that it can get the + // eof and emit a 'close' event. + // Do it on nextTick so that the user has one last chance + // to consume the output, if for example they only want to + // start reading the data once the process exits. + process.nextTick(function() { + flushStdio(self); + }); + maybeClose(self); }; } util.inherits(ChildProcess, EventEmitter); +function flushStdio(subprocess) { + subprocess.stdio.forEach(function(stream, fd, stdio) { + if (!stream || !stream.readable || stream._consuming || + stream._readableState.flowing) + return; + stream.resume(); + }); +} + + + function getHandleWrapType(stream) { if (stream instanceof handleWraps.Pipe) return 'pipe'; if (stream instanceof handleWraps.TTY) return 'tty'; diff --git a/lib/net.js b/lib/net.js index a347c08507..1c581fc3d0 100644 --- a/lib/net.js +++ b/lib/net.js @@ -244,6 +244,15 @@ function onSocketEnd() { exports.Socket = Socket; exports.Stream = Socket; // Legacy naming. +Socket.prototype.read = function(n) { + if (n === 0) + return stream.Readable.prototype.read.call(this, n); + + this.read = stream.Readable.prototype.read; + this._consuming = true; + return this.read(n); +}; + Socket.prototype.listen = function() { debug('socket.listen');