# Set exec command with a text input

**URL:** <https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402>\
**Category:** Dashboard\
**Created:** [21 April 2019 19:03 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402 "2019-04-21T19:03:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiamondWolf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diamondwolf/32/7807_2.png) [@DiamondWolf](https://discourse.nodered.org/u/DiamondWolf)\
**Post date:** [21 April 2019 19:03 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/1 "2019-04-21T19:03:47Z")

</div>

**Hello everybody**

I want to insert the value of an "text input" node in an "exec" node.  
For example when I put "sudo reboot" in the text input and then click a button, my raspberry pi reboots.

And I don't know how I can easily do this.

Thank you !

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 April 2019 19:20 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/2 "2019-04-21T19:20:20Z")

</div>

That is a rather dangerous thing to do, make sure no-one with evil intent can access the dashboard. But if you must, then in the exec node you can select "Append msg.payload to command" (or something similar, I forget the exact wording) and then leave the command empty. Make sure the command you want is in msg.payload.  
I hope you are not running node-red as root, otherwise if someone enters `rm -rf /` bad things will happen.  
**[Edit]** Even if you are not running as root then something like `rm -rf .` would also be pretty bad.

---

<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:** [21 April 2019 19:51 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/3 "2019-04-21T19:51:05Z")

</div>

Note also. If you are not running Node-RED as root then you can't run commands with sudo as that is a privilege escalation. But yes - is a very dangerous thing to do.. I'd advise against it if at all possible.

---

<div class="post-metadata">

**Author:** ![DiamondWolf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diamondwolf/32/7807_2.png) [@DiamondWolf](https://discourse.nodered.org/u/DiamondWolf)\
**Post date:** [21 April 2019 20:07 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/4 "2019-04-21T20:07:42Z")

</div>

Thank you, I know the dangers but it isn't a problem for me.

I only want to put the value of my slider or of the text input behind a command and that's why I asked for this.  
For example shutdown after x minutes :  
shutdown -r +15  
15 is the value of the input box

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 April 2019 20:45 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/5 "2019-04-21T20:45:33Z")

</div>

> [@dceejay](#):
>
> If you are not running Node-RED as root then you can't run commands with sudo as that is a privilege escalation

In fact that isn't correct. Using visudo you can specify that defined commands do not need a password when called with sudo, then that command can be invoked from an exec node. I use this to specify that `sudo reboot` does not need a password so I can reboot the pi if it detects a problem such as network failure, in the hope it will recover. In that case the full command is built into the exec node of course.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 April 2019 20:46 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/6 "2019-04-21T20:46:28Z")

</div>

> [@DiamondWolf](#):
>
> For example shutdown after x minutes :  
> shutdown -r +15  
> 15 is the value of the input box

In that case configure the exec node with the shutdown command and just append the 15 from the payload.

---

<div class="post-metadata">

**Author:** ![DiamondWolf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diamondwolf/32/7807_2.png) [@DiamondWolf](https://discourse.nodered.org/u/DiamondWolf)\
**Post date:** [21 April 2019 21:00 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/7 "2019-04-21T21:00:25Z")

</div>

Yes but I don't know how to insert the payload value in a command  
I'm sorry I don't really know how Nodered works

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 April 2019 21:05 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/8 "2019-04-21T21:05:41Z")

</div>

double click on the exec node and read relation to the info panel on the right hand side

Start by using an inject node to inject the injectable bit into the exec node.

---

<div class="post-metadata">

**Author:** ![DiamondWolf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diamondwolf/32/7807_2.png) [@DiamondWolf](https://discourse.nodered.org/u/DiamondWolf)\
**Post date:** [21 April 2019 21:30 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/9 "2019-04-21T21:30:17Z")

</div>

I read the info panel but it doesn't help me..  
Here is my project, it will probably be easier for you to understand it:

 ![](https://image.noelshack.com/fichiers/2019/16/7/1555882040-slider.png)  
If you don't understand what I am looking for tell me

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 April 2019 21:32 UTC](https://discourse.nodered.org/t/set-exec-command-with-a-text-input/10402/10 "2019-04-21T21:32:28Z")

</div>

forget about the dashboard until you understand how Node-RED works.

This is far easier using an inject node or multiple inject nodes
