mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Normalise spawn behaviour in exec node to accept identical parameters
Can now just tick or untick spawn and command still works.
This commit is contained in:
parent
c232bf5ed6
commit
d5e1468718
@ -37,15 +37,13 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips" id="spawnTip"><span data-i18n="[html]exec.tip"></span></div>
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="exec">
|
<script type="text/x-red" data-help-name="exec">
|
||||||
<p>Calls out to a system command.<br/></p>
|
<p>Calls out to a system command.<br/></p>
|
||||||
<p>Provides 3 outputs... stdout, stderr, and return code.</p>
|
<p>Provides 3 outputs... stdout, stderr, and return code.</p>
|
||||||
<p>By default uses exec() which calls the command, blocks while waiting for completion, and then returns the complete result in one go, along with any errors.</p>
|
<p>By default uses exec() which calls the command, then gets a callback on completion, returning the complete result in one message, along with any errors.</p>
|
||||||
<p>Optionally can use spawn() instead, which returns output from stdout and stderr as the command runs (ie one line at a time). On completion it then returns a return code (on the 3rd output).</p>
|
<p>Optionally can use spawn() instead, which returns the output from stdout and stderr as the command runs (usually one line at a time). On completion it then returns a return code (on the 3rd output).</p>
|
||||||
<p>Spawn only expects one command word, with all extra parameters to be comma separated and passed as the append.</p>
|
|
||||||
<p>The optional append gets added to the command after the <b>msg.payload</b> - so you can do things like pipe the result to another command.</p>
|
<p>The optional append gets added to the command after the <b>msg.payload</b> - so you can do things like pipe the result to another command.</p>
|
||||||
<p>If stdout is binary a <i>buffer</i> is returned - otherwise returns a <i>string</i>.</p>
|
<p>If stdout is binary a <i>buffer</i> is returned - otherwise returns a <i>string</i>.</p>
|
||||||
</script>
|
</script>
|
||||||
@ -70,15 +68,6 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
|
||||||
oneditprepare: function() {
|
|
||||||
$("#node-input-useSpawn").on("change",function() {
|
|
||||||
if ($("#node-input-useSpawn").is(':checked')) {
|
|
||||||
$("#spawnTip").show();
|
|
||||||
} else {
|
|
||||||
$("#spawnTip").hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -34,13 +34,14 @@ module.exports = function(RED) {
|
|||||||
if (this.useSpawn === true) {
|
if (this.useSpawn === true) {
|
||||||
// make the extra args into an array
|
// make the extra args into an array
|
||||||
// then prepend with the msg.payload
|
// then prepend with the msg.payload
|
||||||
if (typeof(msg.payload !== "string")) { msg.payload = (msg.payload || "").toString(); }
|
|
||||||
var pay = [];
|
var arg = node.cmd+" "+msg.payload+" "+node.append;
|
||||||
if ((node.addpay === true) && (msg.payload.toString().trim() !== "")) { pay = msg.payload.split(","); }
|
// slice whole line by spaces (trying to honour quotes);
|
||||||
var arg = pay.concat(node.append.split(","));
|
arg = arg.match(/(?:[^\s"]+|"[^"]*")+/g);
|
||||||
if (RED.settings.verbose) { node.log(node.cmd+" ["+arg+"]"); }
|
var cmd = arg.shift();
|
||||||
if (node.cmd.indexOf(" ") == -1) {
|
if (RED.settings.verbose) { node.log(cmd+" ["+arg+"]"); }
|
||||||
var ex = spawn(node.cmd,arg);
|
if (cmd.indexOf(" ") == -1) {
|
||||||
|
var ex = spawn(cmd,arg);
|
||||||
ex.stdout.on('data', function (data) {
|
ex.stdout.on('data', function (data) {
|
||||||
//console.log('[exec] stdout: ' + data);
|
//console.log('[exec] stdout: ' + data);
|
||||||
if (isUtf8(data)) { msg.payload = data.toString(); }
|
if (isUtf8(data)) { msg.payload = data.toString(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user