# Introduce inputs in exec node

**URL:** <https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118>\
**Category:** General\
**Created:** [14 May 2019 11:33 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118 "2019-05-14T11:33:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [14 May 2019 11:33 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/1 "2019-05-14T11:33:52Z")

</div>

Hello!!  
I'm trying to execute a Java program from node-red in my raspberry pi that consists on entering a name so that it can be displayed as an output, and I wonder how can I introduce the input that I want (the name Mickey Mouse for example), in the exec node so that it can be sent to the program without getting an error, and the output can be displayed: "Welcome Mickey Mouse". This is the flow I'm working on and the java program that is being executed is SalsaHoy.java, which already works by itself on the Raspberry Pi but not when it is called from node-red with this flow:

```auto
[{"id":"ae4103fa.c2bc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7d8029c6.f1c028","type":"exec","z":"ae4103fa.c2bc","command":"cd Java && javac SalsaHoy.java && java SalsaHoy","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Execute SalsaHoy.java","x":610,"y":380,"wires":[["2b6a9acd.0d3736"],[],[]]},{"id":"2b6a9acd.0d3736","type":"debug","z":"ae4103fa.c2bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":830,"y":380,"wires":[]},{"id":"1a3c269a.9341a9","type":"inject","z":"ae4103fa.c2bc","name":"","topic":"","payload":"Mickey Mouse","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":380,"wires":[["7d8029c6.f1c028"]]}]

```

Thank you in advance!!

---

<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:** [14 May 2019 11:53 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/2 "2019-05-14T11:53:06Z")

</div>

Click on node and then read the info tab (in the sidebar)

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [14 May 2019 14:05 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/3 "2019-05-14T14:05:33Z")

</div>

And how do I append the input to the command?

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [14 May 2019 14:21 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/4 "2019-05-14T14:21:45Z")

</div>

Also would help too if anybody could tell me how to run 2 commands that must be run at different times but with the same exec node!

Thank you all!!

---

<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:** [14 May 2019 15:37 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/5 "2019-05-14T15:37:25Z")

</div>

> [@irantxu](#):
>
> And how do I append the input to the command?

Look at the node’s options

If you have to run two different commands, why can you use two nodes?

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [15 May 2019 08:07 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/6 "2019-05-15T08:07:36Z")

</div>

Because the second one is not actually a command, it´s the input Mickey Mouse, which I want the program to receive and present the final Output with: "Welcome Mickey Mouse"

---

<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:** [15 May 2019 11:12 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/7 "2019-05-15T11:12:28Z")

</div>

Please edit your first post and fixed your code. Add a line with three back tic's (`) on the next line start your code and then add a line after your code with three back tics (`)

In your exec node you are not executing one command but three! (that would have been helpful for you to explain in your initial post)  
`cd Java`  
`javac SalsaHoy.java`  
`java SalsaHoy`  
so you are changing the directory, compiling the program and running it.

Since only the last one needs the argument, you might still be able to append the argument to the commands.

Did you read the `exec` node's `info tab` and look at it's `options`?

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [15 May 2019 11:42 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/8 "2019-05-15T11:42:54Z")

</div>

Thanks four your help, I'm not familiar with Node-red and I'm having trouble, I have checked the info tab of the exec node but I haven't found how to append the input in the command... Do you know??

---

<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:** [15 May 2019 12:07 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/9 "2019-05-15T12:07:44Z")

</div>

please edit your first post after reading this thread: [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

Since you have read the info tab for the `exec` node, please copy and paste the section that talks about adding parameters to the command

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [16 May 2019 14:55 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/11 "2019-05-16T14:55:59Z")

</div>

I get this error, do you know what it means??

```auto
 "Command failed: javac SalsaHoy.java && java SalsaHoy "Mickey"↵Exception in thread "main" java.lang.NullPointerException↵→at SalsaHoy.main(SalsaHoy.java:6)↵"

```

---

<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:** [16 May 2019 15:18 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/12 "2019-05-16T15:18:05Z")

</div>

Only what google says

@dceejay Dave can you link commands using the exec node and pass in an argument?

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [16 May 2019 15:21 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/13 "2019-05-16T15:21:46Z")

</div>

This is my flow:

```auto
[{"id":"2b4acc66.585234","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"5db1d847.7d50b8","type":"debug","z":"2b4acc66.585234","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":400,"wires":[]},{"id":"843dc9e6.098f88","type":"inject","z":"2b4acc66.585234","name":"","topic":"","payload":"\"Mickey\"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":400,"wires":[["99aff280.ad6f9"]]},{"id":"99aff280.ad6f9","type":"exec","z":"2b4acc66.585234","command":"javac SalsaHoy.java && java SalsaHoy","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Execute SalsaHoy.java","x":630,"y":400,"wires":[["5db1d847.7d50b8"],[],[]]}]

```

And this is my code:

```auto
import java.io.Console;  
	class SalsaHoy{    
		public static void main(String args[]){    
		Console c=System.console();    
		System.out.println("Enter your name: ");    
		String n=c.readLine();    
		System.out.println("Welcome "+n);    
		}    
	}

```

Iḿ executing this in a Raspberry PI 3 b+  
Thank you in advance!!

---

<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:** [16 May 2019 16:39 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/14 "2019-05-16T16:39:55Z")

</div>

Why are you doing this? You could have someone enter their name in a form in the dashboard and display the greeting on the dashboard using only node-red nodes.

---

<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:** [16 May 2019 18:23 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/15 "2019-05-16T18:23:39Z")

</div>

Yes you can pass in any command string you like. You can create it using a function node or template if you wish.

---

<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:** [16 May 2019 19:10 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/16 "2019-05-16T19:10:49Z")

</div>

But he is concatenation three commands together

---

<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:** [16 May 2019 19:13 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/17 "2019-05-16T19:13:21Z")

</div>

Yeah no problem in Linux

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [17 May 2019 08:51 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/18 "2019-05-17T08:51:00Z")

</div>

Because I am trying to develop a communication between node-red and java, where you can enter inputs from node-red, execute the corresponding code in Java with the inputs sent from node-red and show the output back in the debug window in Node-red. So it is like this is a simple program to figure out how to send inputs from node-red to my program in java but i don know how...  
How would it be done with a function or a template node? So I cannot do it with an inject node injecting a string with the input and then selecting the option "append to msg.payload" in the exec node?  
Thanks again for your help

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [17 May 2019 09:06 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/19 "2019-05-17T09:06:31Z")

</div>

Your command will execute like:

```auto
javac SalsaHoy.java && java SalsaHoy <arguments from msg.payload>

```

Is this what you want ?

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [17 May 2019 09:12 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/20 "2019-05-17T09:12:09Z")

</div>

Yes please!! But if I do that this error comes out:

```auto
Command failed: cd Java/SalsaHoy && javac SalsaHoy.java && java SalsaHoy <arguments from msg.payload> "Mickey"
/bin/sh: 1: cannot open arguments: No such file

```

---

<div class="post-metadata">

**Author:** ![irantxu](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@irantxu](https://discourse.nodered.org/u/irantxu)\
**Post date:** [17 May 2019 09:14 UTC](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118/21 "2019-05-17T09:14:49Z")

</div>

Or if I try the following command:

```auto
cd Java/SalsaHoy && javac SalsaHoy.java && java SalsaHoy <"Mickey">

```

The following error comes out:

```auto
Command failed: cd Java/SalsaHoy && javac SalsaHoy.java && java SalsaHoy <"Mickey">
/bin/sh: 1: Syntax error: end of file unexpected

```

[Next page](https://discourse.nodered.org/t/introduce-inputs-in-exec-node/11118.md?page=2)
