remove requirement for cmd in exec node config + new style info

This commit is contained in:
Dave Conway-Jones 2017-03-29 21:44:58 +01:00
parent 9928e8562a
commit 3f349c3531
3 changed files with 27 additions and 18 deletions

View File

@ -45,24 +45,32 @@
<script type="text/x-red" data-help-name="exec">
<p>Calls out to a system command.<br/></p>
<p>Provides 3 outputs: stdout, stderr, and return code.</p>
<p>By default uses the <code>exec</code> system call which calls the command, waits for it to complete, and
returns the normal output to the first port, any error text to the second port, and a return code object to the
third port. For example a succesful command should return <code>{ code: 0 }</code>.</p>
<p><b>Inputs</b></p>
<ul><li><code>msg.payload</code> - optionally appended to the configured command.</li></ul>
<ul><li><code><i>msg.kill</i></code> - can be used to kill a running command, see below.</li></ul>
<ul><li><code><i>msg.pid</i></code> - can be used to kill a specific running command, see below.</li></ul>
<p><b>Outputs</b></p>
<ol>
<li>stdout, <code>msg.payload</code> containing the returned output from the command.</li>
<li>stderr, <code>msg.payload</code> containing any error output from the command.</li>
<li>return code, <code>msg.payload</code> containing the return (see below).</li>
</ol>
<p><b>Details</b></p>
<p>By default uses the <code>exec</code> system call which calls the command, waits for it to complete, and then
returns the output. For example a succesful command should have a return code of <code>{ code: 0 }</code>.</p>
<p>Optionally can use <code>spawn</code> 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 numeric return code
on the 3rd port. For example a successful command should return <code>0</code>.</p>
<p>The <code>exec</code> method spawns a subshell and therefore can be used for more complicated
commands involving pipes. However, it waits for completion of the whole command before returing anything.</p>
<p>The optional <b>append</b> gets added to the command after <code>msg.payload</code> - so you can do
things like pipe the result to another command.</p>
<p>Commands or parameters with spaces should be enclosed in quotes - <i>"This is a single parameter"</i></p>
<p>The <code>payload</code> is usually a <i>string</i>, unless binary is detected, in which case it contains a <i>buffer</i>.</p>
<p>The returned <code>payload</code> is usually a <i>string</i>, unless non-UTF8 characters are detected, in which
case it contains a <i>buffer</i>.</p>
<p>The blue status icon and PID will be visible while the node is active. This can be read by a <code>status</code> node.</p>
<p>Sending <code>msg.kill</code> will kill a single active process. <code>msg.kill</code> should be a string containing
the type of signal to be sent, e.g. "SIGINT", "SIGQUIT", "SIGHUP", etc. Defaults to "SIGTERM" if blank ("").
If there is more than one process running then <code>msg.pid</code> must also be set with the value of the PID to be killed.</p>
<p><b>Tip: </b>If running a Python app you may need to use the <code>-u</code> parameter to stop the output being buffered.</p>
<p><b>Tip</b>: If running a Python app you may need to use the <code>-u</code> parameter to stop the output being buffered.</p>
</script>
<script type="text/javascript">
@ -70,7 +78,7 @@
category: 'advanced-function',
color:"darksalmon",
defaults: {
command: {value:"",required:true},
command: {value:""},
addpay: {value:true},
append: {value:""},
useSpawn: {value:""},

View File

@ -147,6 +147,7 @@ module.exports = function(RED) {
}
}
});
this.on('close',function() {
for (var pid in node.activeProcesses) {
/* istanbul ignore else */

View File

@ -78,7 +78,7 @@ describe('exec node', function() {
msg = messages[1];
msg.should.have.property("payload");
msg.payload.should.be.a.String,
msg.payload.should.be.a.String;
msg.payload.should.equal("ECHO");
msg = messages[2];
@ -300,7 +300,7 @@ describe('exec node', function() {
msg = messages[1];
msg.should.have.property("payload");
msg.payload.should.be.a.String,
msg.payload.should.be.a.String;
msg.payload.should.equal("ERROR");
msg = messages[2];