Browse Source

child_process: Pull through untouched stdio streams

Otherwise child procs will never emit a 'close' event if you don't
ever consume their streams, because they will never hit the EOF.
v0.9.6-release
isaacs 12 years ago
parent
commit
df3563aa65
  1. 21
      lib/child_process.js
  2. 9
      lib/net.js

21
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';

9
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');

Loading…
Cancel
Save