-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExec.js
More file actions
36 lines (34 loc) · 1.29 KB
/
Copy pathExec.js
File metadata and controls
36 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var noContainer=/Error: No such image or container/;
module.exports = function(RED) {
var child_process=require("child_process");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');
function ExecuteNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.on('input', function(msg) {
var container=msg.payload.Service.toLowerCase()+"_"+msg.payload.S_Tag+"_"+msg.payload.C_Tag;
var command=msg.payload.command;
cmd="docker exec " +container +" "+command;
console.log(cmd);
child_process.exec(cmd,function(error,stdout,stderr){
if(error!=null){
msg.payload.error=stderr;
node.send(msg);
return;
}else{
if(noContainer.test(stdout)){
console.log("didn't exist");
msg.payload.container="None";
}else{
console.log("did exist");
msg.payload.results=stdout;
}
node.send(msg);
}
});
//console.log(strOutcome);
});
}
RED.nodes.registerType("execute",ExecuteNode);
}