From 06adf3d3460bbc54406a09aac8c92b9f6fbb1ebc Mon Sep 17 00:00:00 2001 From: johanneskropf <46578064+johanneskropf@users.noreply.github.com> Date: Wed, 10 Jun 2020 11:24:56 +0200 Subject: [PATCH] use bash as shell for exec command if on linux This relates to: https://github.com/node-red/node-red/issues/2604 and https://discourse.nodered.org/t/exec-node-timeout-not-working-in-exec-mode/28040 and is a possible workaround for most issues related to kill described there. This has only been tested on linux where this change applies so it would most definitely need more testing on windows/mac and maybe linux distributions where there is no bash(?). --- .../node_modules/@node-red/nodes/core/function/90-exec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/90-exec.js b/packages/node_modules/@node-red/nodes/core/function/90-exec.js index f5e7edd87..795343c22 100644 --- a/packages/node_modules/@node-red/nodes/core/function/90-exec.js +++ b/packages/node_modules/@node-red/nodes/core/function/90-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 fs = require('fs'); var isUtf8 = require('is-utf8'); function ExecNode(n) { @@ -122,12 +123,14 @@ module.exports = function(RED) { }); } else { + var execOpt = {encoding:'binary', maxBuffer:10000000}; + if (process.platform === 'linux' && fs.existsSync('/bin/bash')) { execOpt.shell = '/bin/bash'; } var cl = node.cmd; if ((node.addpay === true) && msg.hasOwnProperty("payload")) { cl += " "+msg.payload; } if (node.append.trim() !== "") { cl += " "+node.append; } /* istanbul ignore else */ if (RED.settings.verbose) { node.log(cl); } - child = exec(cl, {encoding:'binary', maxBuffer:10000000}, function (error, stdout, stderr) { + child = exec(cl, execOpt, function (error, stdout, stderr) { var msg2, msg3; delete msg.payload; if (stderr) {