Fix Ping exec calls so regex can then do it's job...

This commit is contained in:
Dave C-J 2014-01-07 15:59:34 +00:00
parent fe04286d10
commit 914885dd6b
1 changed files with 7 additions and 7 deletions

View File

@ -26,14 +26,14 @@ function PingNode(n) {
node.tout = setInterval(function() {
var ex;
if (plat == "linux") ex = spawn('ping', ['-n', '-w 5', '-c 1', node.host]);
else if (plat.match(/^win/)) ex = spawn('ping', ['-n 1', '-w 5000', node.host]);
else if (plat == "darwin") ex = spawn('ping', ['-n', '-t 5', '-c 1', node.host]);
if (plat == "linux") ex = spawn('ping', ['-n', '-w', '5', '-c', '1', node.host]);
else if (plat.match(/^win/)) ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]);
else if (plat == "darwin") ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]);
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
var res="";
var res = "";
ex.stdout.on('data', function (data) {
//console.log('[ping] stdout: ' + data.toString());
var regex = /time=(.*)ms/;
var regex = /time.(.*)ms/;
var m = regex.exec(data.toString())||[""];
res = Number(m[1]);
});
@ -42,8 +42,8 @@ function PingNode(n) {
});
ex.on('close', function (code) {
//console.log('[ping] result: ' + code);
var msg = { payload: false, topic:node.host };
if (code == 0) msg = { payload: res, topic:node.host };
var msg = { payload:false, topic:node.host };
if (code == 0) msg = { payload:res, topic:node.host };
node.send(msg);
});
}, node.timer);