# Feature request - Access OS command line option in Change node

**URL:** <https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807>\
**Category:** Feature Requests\
**Created:** [22 March 2023 09:33 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807 "2023-03-22T09:33:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 March 2023 09:33 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/1 "2023-03-22T09:33:55Z")

</div>

We can use JSONata expressions in the change node, which gives access to powerful data manipulations. I believe a JSONata interpreter is built-in to Node-red:

This proposal is to also allow operating system commands (which would be passed to the os for evaluation, not evaluated by NR)

This will build on Node-red's ability to stitch together nodes and external programs (exec and daemon) _cf_ the pipeline concept in Bash

Some examples using Bash syntax. I'm not sure if it should be DOS commands on Windows or Bash to WSL :

- An eccentric date format requirement: "08 hours on day 081 of 2023" - **`date +"%H hours on day %j of %Y"`**
- How many times today have Node-red flows restarted? - **`grep "Node-RED.*Started flows" /var/log/syslog | wc -l`**
- Create an array [1,2,3,4,5,6,7,8,9,10] - **`printf "%s," {1..10} | sed ' s/,$//'`** (needs additional template node to change string to array)

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc515b75d5764d08468ea95020c054cfa8803933.jpeg)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 March 2023 09:39 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/2 "2023-03-22T09:39:10Z")

</div>

Correct me if I'm wrong, but can't you already do this? I have no problems using JSONata in a change node to output a string. That string can then be passed as input to the exec node.

> [@jbudd](#):
>
> Some examples using Bash syntax. I'm not sure if it should be DOS commands on Windows or Bash to WSL :

And therein lies the problem doesn't it? There are at least 4 or 5 commonly used shells and they all have many different commands.

Feels to me like conflating too many different things into a single node?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 March 2023 09:44 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/3 "2023-03-22T09:44:53Z")

</div>

Yes of course you can use an exec node.

The proposal is to make programming in Node-red more flexible for people who already have familiarity with the CLI of their operating system.

As for multiple shells, if I wanted a C shell command I would just prefix the command with csh. The OS handles it invisibly.

> [@TotallyInformation](#):
>
> Feels to me like conflating too many different things into a single node?

I agree, there are a lot of change node options. Maybe you would like to remove JSONata to it's own node to reduce the list? 🙃

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 March 2023 09:46 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/4 "2023-03-22T09:46:40Z")

</div>

Still feels like a lot of complexity to squeeze into a single node - but that's only my opinion of course. 😁

> [@jbudd](#):
>
> I agree, there are a lot of change node options. Maybe you would like to remove JSONata to it's own node to reduce the list? 🙃

But that directly relates to _changing_ things on a msg. Running OS commands seems different to me.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 March 2023 12:03 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/5 "2023-03-22T12:03:57Z")

</div>

The examples I gave above directly relate to changing a message; except for counting NR deploys you can do them with Javascript in a function node.

I struggle to understand this objection.  
People use Node-red in different ways for example [some-parental-control-with-nodered-and-a-windows-pc](https://discourse.nodered.org/t/some-parental-control-with-nodered-and-a-windows-pc/76808/2) or  
[integrating-node-red-mcu-edition-into-the-node-red-editor](https://discourse.nodered.org/t/node-red-mcu-plugin-v1-0-integrating-node-red-mcu-edition-into-the-node-red-editor/72693/68)  
Do you object to these on the basis that it's somewhat different to "normal" Node-red philosophy?

Yes it might allow me to run some application which would be _better_ launched from an exec node. I wouldn't choose to start an xterminal and open a browser from a change node, but if I did, so what?

What it would do is allow me to more easily use my knowledge of the shell as an alternative perhaps to learning yet another language - JSONata.

The long dropdown of change node options is certainly a problem but if necessary it could be broken down into categories.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 March 2023 12:54 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/6 "2023-03-22T12:54:24Z")

</div>

I would be against this simply because it would be making something simple more complex and the more complex things gets, the more issues crop up. A node should do one thing and do it well. As I understand it, JSONata is included as part of node-red so it is not an external program.

The exec node's job is to exec external programs and that is what it does. So if you need to run some special script to make a change to something, the exec node is there for you to use.

My two cents.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 March 2023 12:59 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/7 "2023-03-22T12:59:38Z")

</div>

> [@jbudd](#):
>
> I struggle to understand this objection

I'm not objecting really, but rather commenting based on what I know about Node-RED philosophy over the years 🙂

Heaven knows I tend to pack far too much into my own nodes. 🤣

> [@jbudd](#):
>
> Do you object to these on the basis that it's somewhat different to "normal" Node-red philosophy?

What we do with our own custom nodes is in a different league to what happens to core nodes though.

So if you were suggesting a custom node with this capability, I might comment about similarity with other nodes but that would be all.

Don't get me wrong - my comments were just that, comments about a suggestion. Of course, it won't be down to me what changes might or might not happen to a core node.

At the end of the day, it wouldn't bother me if another option were added as long as it was backwards compatible and didn't add bloat to Node-RED.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [22 March 2023 18:36 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/8 "2023-03-22T18:36:33Z")

</div>

> [@jbudd](#):
>
> I wouldn't choose to start an xterminal and open a browser from a change node, but if I did, so what?

I have some concern about this. At present, the `change` node can only operate on messages and should not produce any side effects. The `exec` mode is much more capable and should be used with caution. If I imported a flow from this forum or an example for a node in the palette, I definitely would open any `exec` node to be sure that nothing malicious or misguided was going on inside. I would hate to have to do this with every `change` node.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 March 2023 19:28 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/9 "2023-03-22T19:28:17Z")

</div>

this would make flows using the change node platform specific. I would prefer to keep anything specific to as few places as possible. Further we currently allow blocking of certain nodes in order to help security - and often that is the exec node to prevent things like rm - r :-)...

We can't block parts of nodes - and having users have to poke around inside nodes to work out why it works on one platform and not on another is not something we would not want to do lightly.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 March 2023 22:41 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/10 "2023-03-22T22:41:56Z")

</div>

I concede defeat and limp off with just a couple of questions

> [@dceejay](#):
>
> This would make flows using the change node platform specific.

Does the js code to run bash commands in 90-exec.js make the exec node platform specific? (Don't think I have ever successfully installed NR on Windows so no chance to test it).

> [@dceejay](#):
>
> I would prefer to keep ... to as few places as possible.

OK it makes sense to only allow :(){ :|:& };: or sudo rm ... in exec (or daemon, some contrib nodes, ...)

> [@dceejay](#):
>
> Further we currently allow blocking of certain nodes

How?

Is it impossible to use child\_process.exec() in a fnction node? I have seen some discussion about that

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 May 2023 22:42 UTC](https://discourse.nodered.org/t/feature-request-access-os-command-line-option-in-change-node/76807/11 "2023-05-21T22:42:31Z")

</div>

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