From 547ae0cd72e5e75a336380a4078cb4e7bd4fc388 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 19 Oct 2013 14:58:05 +0100 Subject: [PATCH] Added a bit more error cathing to tail node --- nodes/storage/28-tail.js | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/nodes/storage/28-tail.js b/nodes/storage/28-tail.js index 164b77bfb..dbf68b22b 100644 --- a/nodes/storage/28-tail.js +++ b/nodes/storage/28-tail.js @@ -19,33 +19,38 @@ var fs = require("fs"); var spawn = require('child_process').spawn; function TailNode(n) { - RED.nodes.createNode(this,n); + RED.nodes.createNode(this,n); - this.filename = n.filename; - this.split = n.split; - var node = this; + this.filename = n.filename; + this.split = n.split; + var node = this; - var tail = spawn("tail", ["-f", this.filename]); - tail.stdout.on("data", function (data) { - var msg = {topic:node.filename}; - if (node.split) { - var strings = data.toString().split("\n"); - for (s in strings) { - if (strings[s] != "") { - msg.payload = strings[s]; - node.send(msg); - } - } - } - else { - msg.payload = data.toString(); - node.send(msg); - } - }); - - this.on("close",function() { - tail.kill(); - }); + var err = ""; + var tail = spawn("tail", ["-f", this.filename]); + tail.stdout.on("data", function (data) { + var msg = {topic:node.filename}; + if (node.split) { + var strings = data.toString().split("\n"); + for (s in strings) { + if (strings[s] != "") { + msg.payload = strings[s]; + node.send(msg); + } + } + } + else { + msg.payload = data.toString(); + node.send(msg); + } + }); + + tail.stderr.on("data", function(data) { + node.warn(data.toString()); + }); + + this.on("close", function() { + if (tail) tail.kill(); + }); } RED.nodes.registerType("tail",TailNode);