mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Added a bit more error cathing to tail node
This commit is contained in:
parent
b1c9e95209
commit
547ae0cd72
@ -19,33 +19,38 @@ var fs = require("fs");
|
|||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
|
|
||||||
function TailNode(n) {
|
function TailNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
this.split = n.split;
|
this.split = n.split;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
var tail = spawn("tail", ["-f", this.filename]);
|
var err = "";
|
||||||
tail.stdout.on("data", function (data) {
|
var tail = spawn("tail", ["-f", this.filename]);
|
||||||
var msg = {topic:node.filename};
|
tail.stdout.on("data", function (data) {
|
||||||
if (node.split) {
|
var msg = {topic:node.filename};
|
||||||
var strings = data.toString().split("\n");
|
if (node.split) {
|
||||||
for (s in strings) {
|
var strings = data.toString().split("\n");
|
||||||
if (strings[s] != "") {
|
for (s in strings) {
|
||||||
msg.payload = strings[s];
|
if (strings[s] != "") {
|
||||||
node.send(msg);
|
msg.payload = strings[s];
|
||||||
}
|
node.send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
msg.payload = data.toString();
|
else {
|
||||||
node.send(msg);
|
msg.payload = data.toString();
|
||||||
}
|
node.send(msg);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
this.on("close",function() {
|
|
||||||
tail.kill();
|
tail.stderr.on("data", function(data) {
|
||||||
});
|
node.warn(data.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("close", function() {
|
||||||
|
if (tail) tail.kill();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("tail",TailNode);
|
RED.nodes.registerType("tail",TailNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user