mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add rc property to exec node outputs 1 and 2 (#1401)
* Add rc property to exec node outputs 1 and 2 to close #1399 * improve test coverage and add tests for new msg.rc * make spawn test slightly more robust to different environments * added debug for spawn test * let spawn error test be even more relaxed * don't necessarily clone msg.payload in exec node stderr as per suggestion
This commit is contained in:
committed by
Nick O'Leary
parent
848fb975ed
commit
2b9aa94f3a
@@ -75,12 +75,20 @@
|
||||
<dt>payload <span class="property-type">string</span></dt>
|
||||
<dd>the standard output of the command.</dd>
|
||||
</dl>
|
||||
<dl class="message-properties">
|
||||
<dt>rc <span class="property-type">object</span></dt>
|
||||
<dd>exec mode only, a copy of the return code object (also available on port 3)</dd>
|
||||
</dl>
|
||||
</li>
|
||||
<li>Standard error
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">string</span></dt>
|
||||
<dd>the standard error of the command.</dd>
|
||||
</dl>
|
||||
<dl class="message-properties">
|
||||
<dt>rc <span class="property-type">object</span></dt>
|
||||
<dd>exec mode only, a copy of the return code object (also available on port 3)</dd>
|
||||
</dl>
|
||||
</li>
|
||||
<li>Return code
|
||||
<dl class="message-properties">
|
||||
|
@@ -125,14 +125,15 @@ module.exports = function(RED) {
|
||||
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, {encoding:'binary', maxBuffer:10000000}, function (error, stdout, stderr) {
|
||||
var msg2, msg3;
|
||||
delete msg.payload;
|
||||
if (stderr) {
|
||||
msg2 = RED.util.cloneMessage(msg);
|
||||
msg2.payload = stderr;
|
||||
}
|
||||
msg.payload = Buffer.from(stdout,"binary");
|
||||
if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); }
|
||||
var msg2 = null;
|
||||
if (stderr) {
|
||||
msg2 = {payload: stderr};
|
||||
}
|
||||
var msg3 = null;
|
||||
node.status({});
|
||||
//console.log('[exec] stdout: ' + stdout);
|
||||
//console.log('[exec] stderr: ' + stderr);
|
||||
@@ -142,10 +143,15 @@ module.exports = function(RED) {
|
||||
if (error.code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); }
|
||||
else { node.status({fill:"red",shape:"dot",text:"error:"+error.code}); }
|
||||
node.log('error:' + error);
|
||||
} else if (node.oldrc === "false") {
|
||||
}
|
||||
else if (node.oldrc === "false") {
|
||||
msg3 = {payload:{code:0}};
|
||||
}
|
||||
if (!msg3) { node.status({}); }
|
||||
else {
|
||||
msg.rc = msg3.payload;
|
||||
if (msg2) { msg2.rc = msg3.payload; }
|
||||
}
|
||||
node.send([msg,msg2,msg3]);
|
||||
if (child.tout) { clearTimeout(child.tout); }
|
||||
delete node.activeProcesses[child.pid];
|
||||
|
Reference in New Issue
Block a user