Skip to content

Commit

Permalink
Handle Socket.closed errors on run_synced().
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed Apr 29, 2014
1 parent ff3ac34 commit 5345e2e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/conf/helpers.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 5345e2e

Please sign in to comment.