2 * Copyright 2013, 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 module.exports = function(RED) {
19 var spawn = require('child_process').spawn;
20 var plat = require('os').platform();
22 if (plat.match(/^win/)) {
23 throw "Info : Currently not supported on Windows.";
26 function TailNode(n) {
27 RED.nodes.createNode(this,n);
29 this.filename = n.filename;
34 // TODO: rewrite to use node-tail
35 var tail = spawn("tail", ["-F", "-n", "0", this.filename]);
36 tail.stdout.on("data", function (data) {
38 // TODO: allow customisation of the line break - as we do elsewhere
39 var strings = data.toString().split("\n");
40 for (var s in strings) {
41 //TODO: should we really filter blanks? Is that expected?
42 if (strings[s] !== "") {
53 payload: data.toString()
59 tail.stderr.on("data", function(data) {
60 node.warn(data.toString());
63 this.on("close", function() {
64 if (tail) { tail.kill(); }
68 RED.nodes.registerType("tail",TailNode);