From ee0bd49918db1becdb0b166c8e43340c6b06402b Mon Sep 17 00:00:00 2001
From: cinhcet 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.
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];