Exec node - piping payload to stdin for commands

Screenshot 2024-09-13 at 14.42.18

So that's what it would look like - I still have to do the server code to support the new option.

EDIT: and also the logic to deactivate the dropdown if append isn't checked :frowning_face:

1 Like

Ok the UI is now this:

execwithpipe

The code for the node is over at FlowHub (with an explanation on how to install the node locally) with an example flow and for those interested in how I did this, the blog post with screencast.

Btw, it's much less code doing it this way, thanks for the suggestion @dceejay!

Btw2: even if the gif seems to be different, parameter is the default value not stdin. I added an extra new parameter 'addpayTo' for storing the location.

looks good - will you make it into a PR against the core node please ?

Thanks

PS - the options are usually not capitalised. So just parameter and stdin please.

I can do that, interested to know what I did wrong!

done.

1 Like

Nothing so far ! (as far as I can tell)

PR is up ==> Exec Node: Allow msg.payload to be redirected to stdin for the process by gorenje · Pull Request #4880 · node-red/node-red · GitHub

At the danger of being (rightly probably) told off by Dave, again. :grinning:

Your command needs to be python and not the shell, then you don't need the hash-bang. But you do need to then deal with passing the whole script as a string.

These threads seem to offer some ideas on the subject:

There’s a million roads that lead to Rome but they all end in Rome.

Of course there are many approaches to handling scripts and doing exec outside of node red. This is just one.

I’ve put up a PR and it’s up to those who decide whether this approach fits into the concept that is node red.

I don’t much mind since node red is so flexible that I can develop my approach outside of the core of node red. And that is the great thing about node red.

2 Likes

Doesn't this break the spawn mode ? and what happens to the 'extra input parameters' ?

Works for spawn and exec mode and the payload can either be appended as input parameter or streamed to stdin - it's either or, not both. By default payload is appended to the parameter if append is activated. If append is not activated, nothing happens with the payload.

1 Like

To answer this question, I had to look at the documentation:

var arg = node.cmd;
if (node.addpay) {
    var value = RED.util.getMessageProperty(msg, node.addpay);
    if (value !== undefined) {
        arg += " " + value;
    }
}
if (node.append.trim() !== "") { arg += " " + node.append; }

So if cmd - i.e. the command is left blank - and append is activated, then the payload (in other words) becomes the command - if that's the parameter that I'm appending!

If append is not activated but there has been an append string defined, then that.

That could be documented since I didn't find that in the documentation for the exec node and I just ran into the use case I want to defined a dynamic command line - how do I do that? - I had to look at the codebase to figure it out ... it wasn't described in the documentation - unfortunately.

Mea culpa: I didn't add any documentation for the feature described here :face_with_open_eyes_and_hand_over_mouth:

/cc @jbudd

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.