mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Allow msg.start to append arguments
This commit is contained in:
parent
5bb8b4d968
commit
99827f5019
@ -15,15 +15,20 @@ module.exports = function(RED) {
|
|||||||
this.closer = n.closer || "SIGKILL";
|
this.closer = n.closer || "SIGKILL";
|
||||||
this.autorun = true;
|
this.autorun = true;
|
||||||
if (n.autorun === false) { this.autorun = false; }
|
if (n.autorun === false) { this.autorun = false; }
|
||||||
if (this.args.match(/^\[.*\]$/)) {
|
this.args = parseArgs(this.args);
|
||||||
try { this.args = JSON.parse(this.args); }
|
var node = this;
|
||||||
|
var lastmsg = {};
|
||||||
|
|
||||||
|
function parseArgs(args) {
|
||||||
|
if (args.match(/^\[.*\]$/)) {
|
||||||
|
try { args = JSON.parse(args); }
|
||||||
catch(e) {
|
catch(e) {
|
||||||
node.warn(RED._("daemon.errors.badparams"))
|
node.warn(RED._("daemon.errors.badparams"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { this.args = this.args.match(/("[^"]*")|[^ ]+/g); }
|
else { args = args.match(/("[^"]*")|[^ ]+/g); }
|
||||||
var node = this;
|
return args;
|
||||||
var lastmsg = {};
|
}
|
||||||
|
|
||||||
function inputlistener(msg) {
|
function inputlistener(msg) {
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
@ -32,7 +37,11 @@ module.exports = function(RED) {
|
|||||||
node.child.kill(msg.kill.toUpperCase());
|
node.child.kill(msg.kill.toUpperCase());
|
||||||
}
|
}
|
||||||
else if (msg.hasOwnProperty("start") && !node.running) {
|
else if (msg.hasOwnProperty("start") && !node.running) {
|
||||||
runit();
|
let args = "";
|
||||||
|
if (msg.hasOwnProperty("args") && msg.args.length > 0) {
|
||||||
|
args = parseArgs(msg.args.trim());
|
||||||
|
}
|
||||||
|
runit(args);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!Buffer.isBuffer(msg.payload)) {
|
if (!Buffer.isBuffer(msg.payload)) {
|
||||||
@ -48,15 +57,20 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runit() {
|
function runit(appendArgs) {
|
||||||
var line = "";
|
var line = "";
|
||||||
if (!node.cmd || (typeof node.cmd !== "string") || (node.cmd.length < 1)) {
|
if (!node.cmd || (typeof node.cmd !== "string") || (node.cmd.length < 1)) {
|
||||||
node.status({fill:"grey",shape:"ring",text:RED._("daemon.status.nocommand")});
|
node.status({fill:"grey",shape:"ring",text:RED._("daemon.status.nocommand")});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let args = node.args;
|
||||||
|
if (appendArgs !== undefined && appendArgs.length > 0) {
|
||||||
|
args = args.concat(appendArgs);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.child = spawn(node.cmd, node.args);
|
node.child = spawn(node.cmd, args);
|
||||||
node.debug(node.cmd+" "+JSON.stringify(node.args));
|
node.debug(node.cmd+" "+JSON.stringify(args));
|
||||||
node.status({fill:"green",shape:"dot",text:RED._("daemon.status.running")});
|
node.status({fill:"green",shape:"dot",text:RED._("daemon.status.running")});
|
||||||
node.running = true;
|
node.running = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user