Two screencasts present the development of the ExecWithPipe custom node.
It was a question of how to count users logged into raspberry that brought me to creating the execWithPipe node. The solution was to use who | wc -l
- a pipe in an exec node! I was not happy with that because I see Node-RED flows as describing pipes - so in a node in a flow there is a Unix pipe - argh! I didn’t like that.
So I asked in the forum whether it would make sense to be able to pipe the contents of msg.payload
into the stdin of the command process. Basically the output of the who
command would be passed out in the msg.payload
attribute and then streamed to the stdin of the wc -l
command. This would be represented like this:
This for me is more Node-RED-like but this is not possible with the current (at time of writing) exec node. The payload can only be added to the command line of the command being executed, not streamed to stdin. There are number of work arounds for this but, for me, the most obvious solution would be to pipe the contents of msg.payload
into stdin.
I decided to quickly create the node and see whether what I was proposing would work. These screencasts describe that process.
How to create flows in Node-RED that represent Node-RED custom nodes? This episode takes advantage of the NodeDev package to create a custom node inside Node-RED that can be installed, extended and developed in Node-RED - no text editor required!
The second part of the screencasts shows how I copy the code of the existing exec node to my custom node. This then allows me to extend it with the functionality I’m looking for.
(Approx. 25mins)
Links
This episode shows how to extend custom node with the new functionality within Node-RED. In this case adding the piping of msg.payload
into stdin of the process that executes the command.
It also demonstrates my development process for creating Node-RED custom nodes. It all happens within Node-RED so that I’m saved the mental context switching of going from my text editor to my visual editor.
(Approx. 20mins)
Links:
The execWithPipe
node indeed does work even (as discussed in the forum) the UI is a dumpster fire waiting to happen. I was not concerned with the UI, after all, I’m not releasing the node as a community node.
Instead if you want to use the execWithPipe
node, then you will have to install it via FlowHub - see the installation instructions over here.
If this becomes popular or there is a need for this functionality, then it should really be incorporated into the existing exec node - keep it simple and avoid duplication.