From 952c7d1b478cc7c6de82475a17a1387992e8651f Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Wed, 12 Jul 2017 23:03:52 +0200 Subject: [PATCH] CLI: Wait for both the 'end' and 'close' event to happen before finishing in pbts, see #863 --- cli/pbts.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/pbts.js b/cli/pbts.js index 245361678..f7ff6e4d1 100644 --- a/cli/pbts.js +++ b/cli/pbts.js @@ -106,9 +106,15 @@ exports.main = function(args, callback) { maxBuffer: 1 << 24 // 16mb }); var out = []; + var ended = false; + var closed = false; child.stdout.on("data", function(data) { out.push(data); }); + child.stdout.on("end", function() { + if (closed) finish(); + else ended = true; + }); child.stderr.pipe(process.stderr); child.on("close", function(code) { // clean up temporary files, no matter what @@ -123,6 +129,11 @@ exports.main = function(args, callback) { throw err; } + if (ended) finish(); + else closed = true; + }); + + function finish() { var output = []; if (argv.global) output.push( @@ -149,7 +160,7 @@ exports.main = function(args, callback) { return callback(err); throw err; } - }); + } } return undefined;