diff --git a/nodes/core/core/75-exec.html b/nodes/core/core/75-exec.html index 0f3a11c59..6aa423fb4 100644 --- a/nodes/core/core/75-exec.html +++ b/nodes/core/core/75-exec.html @@ -47,10 +47,13 @@

Calls out to a system command.

Provides 3 outputs: stdout, stderr, and return code.

By default uses the exec system call which calls the command, then gets a callback - on completion, returning the complete result in one message, along with any errors.

+ on completion, returning stdout as the payload to the first, the error code as the third + and, if available, stderr to the second output. If no error occurred, a zero is returned on the third output.

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).

+

The exec 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.

The optional append gets added to the command after msg.payload - so you can do things like pipe the result to another command.

Commands or parameters with spaces should be enclosed in quotes - "This is a single parameter"

diff --git a/nodes/core/core/75-exec.js b/nodes/core/core/75-exec.js index 546a3f130..0847957a4 100644 --- a/nodes/core/core/75-exec.js +++ b/nodes/core/core/75-exec.js @@ -102,15 +102,19 @@ module.exports = function(RED) { child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) { msg.payload = new Buffer(stdout,"binary"); if (isUtf8(msg.payload)) { msg.payload = msg.payload.toString(); } - var msg2 = {payload:stderr}; - var msg3 = null; + var msg2 = null; + if(stderr) { + msg2 = {payload: stderr}; + } + var msg3 = {payload:0}; + node.status({}); //console.log('[exec] stdout: ' + stdout); //console.log('[exec] stderr: ' + stderr); if (error !== null) { - msg3 = {payload:error}; + msg3 = {payload:error.code}; + node.status({fill:"red",shape:"dot",text:"error: "+error.code}); //console.log('[exec] error: ' + error); } - node.status({}); node.send([msg,msg2,msg3]); if (child.tout) { clearTimeout(child.tout); } delete node.activeProcesses[child.pid];