From 00429ebe70ebb737e96eccb503db2d32019ea959 Mon Sep 17 00:00:00 2001 From: dceejay Date: Wed, 7 Jan 2015 21:12:01 +0000 Subject: [PATCH] Update exec node to handle binary stdout --- nodes/core/core/75-exec.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nodes/core/core/75-exec.js b/nodes/core/core/75-exec.js index 65b39baf8..a56c3f15b 100644 --- a/nodes/core/core/75-exec.js +++ b/nodes/core/core/75-exec.js @@ -18,6 +18,7 @@ module.exports = function(RED) { "use strict"; var spawn = require('child_process').spawn; var exec = require('child_process').exec; + var isUtf8 = require('is-utf8'); function ExecNode(n) { RED.nodes.createNode(this,n); @@ -40,12 +41,14 @@ module.exports = function(RED) { var ex = spawn(node.cmd,arg); ex.stdout.on('data', function (data) { //console.log('[exec] stdout: ' + data); - msg.payload = data.toString(); + if (isUtf8(data)) { msg.payload = data.toString(); } + else { msg.payload = data; } node.send([msg,null,null]); }); ex.stderr.on('data', function (data) { //console.log('[exec] stderr: ' + data); - msg.payload = data.toString(); + if (isUtf8(data)) { msg.payload = data.toString(); } + else { msg.payload = new Buffer(data); } node.send([null,msg,null]); }); ex.on('close', function (code) { @@ -63,7 +66,7 @@ module.exports = function(RED) { else { var cl = node.cmd+" "+msg.payload+" "+node.append; if (RED.settings.verbose) { node.log(cl); } - var child = exec(cl, function (error, stdout, stderr) { + var child = exec(cl, {encoding: 'binary'}, function (error, stdout, stderr) { msg.payload = stdout; var msg2 = {payload:stderr}; var msg3 = null;