mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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.
This commit is contained in:
parent
3e6f737eaf
commit
df3563aa65
@ -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';
|
||||
|
@ -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…
Reference in New Issue
Block a user