Let exec node (spawn) handle commands with spaces in path

This commit is contained in:
Dave Conway-Jones 2017-01-06 09:55:52 +00:00
parent 555f96cfaf
commit 08b11addec
2 changed files with 2 additions and 1 deletions

View File

@ -53,7 +53,7 @@
(on the 3rd output).</p>
<p>The optional append gets added to the command after <code>msg.payload</code> - so you can do
things like pipe the result to another command.</p>
<p>Parameters with spaces should be enclosed in quotes - <i>"This is a single parameter"</i></p>
<p>Commands or parameters with spaces should be enclosed in quotes - <i>"This is a single parameter"</i></p>
<p>If stdout is binary a <i>buffer</i> is returned - otherwise returns a <i>string</i>.</p>
<p>The blue status icon will be visible while the node is active.</p>
<p>If running a Python app you may need to use the <code>-u</code> parameter to stop the output being buffered.</p>

View File

@ -49,6 +49,7 @@ module.exports = function(RED) {
// slice whole line by spaces (trying to honour quotes);
arg = arg.match(/(?:[^\s"]+|"[^"]*")+/g);
var cmd = arg.shift();
if (/^".*"$/.test(cmd)) { cmd = cmd.slice(1,-1); }
/* istanbul ignore else */
if (RED.settings.verbose) { node.log(cmd+" ["+arg+"]"); }
child = spawn(cmd,arg);