From 5345e2e84739fb7469ed5dc43f556236e6d683bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Pollak?= Date: Tue, 29 Apr 2014 01:29:44 -0700 Subject: [PATCH] Handle Socket.closed errors on run_synced(). --- lib/conf/helpers.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/conf/helpers.js b/lib/conf/helpers.js index 6677a76b5..80e498872 100644 --- a/lib/conf/helpers.js +++ b/lib/conf/helpers.js @@ -1,4 +1,5 @@ -var spawn = require('child_process').spawn; +var util = require('util'), + spawn = require('child_process').spawn; /** * Make sure all parameters specified in array are available from command line @@ -36,17 +37,22 @@ exports.run_synced = function(cmd, args, opts, cb){ var timer, child = spawn(cmd, args, opts || {}); + var print = function(str) { + if (process.stdout.writable) + util.puts(str); + } + child.stdout.on('data', function(data){ - console.log(data.toString().replace(/\n$/, '')); + print(data.toString().replace(/\n$/, '')); }) child.stderr.on('data', function(data){ - console.log(data.toString().trim()); + print(data.toString().trim()); }) child.on('exit', function(code){ if (timer) clearTimeout(timer); - console.log('Exited with code ' + code); + print('Exited with code ' + code); cb(code); });