1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add try catch to exec node stdout if utf8 check fails

This commit is contained in:
dceejay 2015-04-24 15:11:59 +01:00
parent 8f8ee4662d
commit 7b4cbbe816

View File

@ -23,7 +23,7 @@ module.exports = function(RED) {
function ExecNode(n) { function ExecNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.cmd = (n.command || "").trim(); this.cmd = (n.command || "").trim();
if (n.addpay == undefined) { n.addpay = true; } if (n.addpay === undefined) { n.addpay = true; }
this.addpay = n.addpay; this.addpay = n.addpay;
this.append = (n.append || "").trim(); this.append = (n.append || "").trim();
this.useSpawn = n.useSpawn; this.useSpawn = n.useSpawn;
@ -72,7 +72,11 @@ module.exports = function(RED) {
if (RED.settings.verbose) { node.log(cl); } if (RED.settings.verbose) { node.log(cl); }
var child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) { var child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
msg.payload = new Buffer(stdout,"binary"); msg.payload = new Buffer(stdout,"binary");
try {
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); } if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
} catch(e) {
node.log("Bad STDOUT");
}
var msg2 = {payload:stderr}; var msg2 = {payload:stderr};
var msg3 = null; var msg3 = null;
//console.log('[exec] stdout: ' + stdout); //console.log('[exec] stdout: ' + stdout);