# Execute dos command in node-red

**URL:** <https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809>\
**Category:** General\
**Created:** [29 March 2020 02:22 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809 "2020-03-29T02:22:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 02:22 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/1 "2020-03-29T02:22:17Z")

</div>

How to use node red to run dos command to execute software application?

I am new user and I want to learn how I can use node-red to automatically execute DOS command for Real Time Optimization (RTO) model from another software application to perform algorithms and data integration .

Can you please advise how which node I should use?

my first attempt in node-red was successfully done reading a CSV file using the flow shown in the screenshot below.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9e48bdcdda0b1e149ce9f7398fe3b1f98cf79c2b.png)

Please, advise me on what node I should use to run multiple instances of node-red to execute dos command for an optimization model and read the results from node-red workspace - I am very excited to work on this, thanks in advance.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 02:33 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/2 "2020-03-29T02:33:13Z")

</div>

Ok, you need to expand on the command and how you are _creating_ it.

The screen shot - though useful in some ways - doesn't really tell anyone much.

Open the `function` node and paste the code in your reply. (Formatting it with the `</>` icon at the top.

And maybe show what is in that big brown node.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 02:44 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/3 "2020-03-29T02:44:36Z")

</div>

The function node is basically specifying the path for the csv file i.e.,

```auto
 <//C:\IMPL\HeatExchanger\MassBalancing.dta;
return msg;>

```

The file in node is named as (`C:\IMPL\HeatExchanger\MassBalancing.dta`)

The software application I use is called Industrial Modeling and programming Language (IMPL) which is DOS executable Optimization program that is CSV based.

My goal is to create a dashboard for the program in node-red.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 02:53 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/4 "2020-03-29T02:53:47Z")

</div>

(I'm not the sharpest tool in the shed)

I think you are going to have to elaborate then on _where_ the command is in the flow.

Maybe tell _us_ what the command is. (And path may be handy too)

Because that didn't really help me help you.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 03:11 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/5 "2020-03-29T03:11:29Z")

</div>

I have not used node-red to execute the command. I wanted to learn how I can go about doing that.

A command for executing an IMPL file is executed using IMPL - Executable (console) as shown below

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c740411228854cbfa8682e6069d09d8ba329bdcf.png)

This command would result in generating multiple csv files for which an optimization result is shown. For example, in this case I am reading MassBalancing.dta file which reconciled result for heat exchanger case study. You can see the generated files below -

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/6529aa562a2f5919939f762ac5a0dc8f6e8d5070.png)

The idea is to execute the last line (impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe\_y12m) from node-red, that would basically allow for IMPL to run the case study and generate multiple CSV files

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 03:14 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/6 "2020-03-29T03:14:51Z")

</div>

I think you have exceeded my skill set by a large amount.

The `exe` node is for simple(ish) commands.

I don't know if it can do that.

One way around it is to make a `.bat` file and have it do the work at the _DOS_ level.

So all node-red would need to do is execute the `.bat` file.

With me?

Good luck.

(Sorry, I'm also great at editing my posts)

The node would look something like:

```auto
[{"id":"77834c75.b8d834","type":"exec","z":"1d85b106.5dfcd7","command":"program_name_here","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":3990,"y":1360,"wires":[[],[],[]]}]

```

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 03:29 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/7 "2020-03-29T03:29:52Z")

</div>

Not really! I do have a .bat file at the DOS level which is meant to clean up CSV generated files.

Can you please elaborate on that ( .bat file and exe node) a bit further? It may help me speed up the learning process.

I understand that you aren't familiar with the scope of the work that IMPL is about but I was trying to simplify my questions putting up all of the above information.

Thank you for your feedback on this.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 03:34 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/8 "2020-03-29T03:34:57Z")

</div>

.bat is not a node.

AFAIK, .bat is a windows _batch_ file which is used by the user for repeated complex commands that need to be done.

Which is sort of what you are wanting to do.

So, in your _terminal_ (or CLI) you enter these commands........  
Put them in a .bat file and let that side of the O/S do the work.

All you need Node-red then to do is invoke that .bat file.  
And what you have written you do know how to make them.

> [@Munier](#):
>
> Not really!

That has no context for me considering what you said immediately after it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 03:36 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/9 "2020-03-29T03:36:24Z")

</div>

> [@Munier](#):
>
> I understand that you aren't familiar with the scope of the work that IMPL

I'm not familiar with much at all really. I just parse things I read and hope the output works.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 03:46 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/10 "2020-03-29T03:46:46Z")

</div>

> [@Munier](#):
>
> The idea is to execute the last line (impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe\_y12m) from node-red, that would basically allow for IMPL to run the case study and generate multiple CSV files

Why are you wanting to _complicate_ things and use Node-Red?  
What part will Node-Red do to help you do this?

This is further complicated by your first post:

> [@Munier](#):
>
> Please, advise me on what node I should use to run multiple instances of node-red to execute dos command for an optimization model and read the results from node-red workspace - I am very excited to work on this, thanks in advance.

Why?  
(do you think Node-Red will help)

I am suspicious you are not using the correct tool for the job.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 03:48 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/11 "2020-03-29T03:48:42Z")

</div>

OK. Thanks for your advice. Yes, that sounds fine to me.

I understand that .bat is not a node.

Now, you mean I should create a .bat file with the command  
(impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe\_y12m)  
in C:\IMPL\HeatExchanger  
Then use the exe node to execute the command from node-red, correct?

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 03:53 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/12 "2020-03-29T03:53:34Z")

</div>

I believe node-red will allow me bring about IIOT using such scope of combining algorithms and integration in one single platform. Software companies such as KBC advanced technology is using similar structure on what I am trying to create with node-red.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 04:01 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/13 "2020-03-29T04:01:03Z")

</div>

Can you please explain the exe node a bit.

Now after creating the .bat file I have to use exe node which would look like this?

```auto
[{"id":"77834c75.b8d834","type":"exec","z":"1d85b106.5dfcd7","impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe_y12m":"C:\IMPL>","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":3990,"y":1360,"wires":[[],[],[]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 04:04 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/14 "2020-03-29T04:04:31Z")

</div>

Ok, I'm going to take a step back for a second.

Your first post - which I can sort of understand - was vague. No specifics. Ok, you are _testing the water_.

> [@Munier](#):
>
> impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe\_y12m

Was never really mentioned.  
If it is **one** command, it is redundant making a .bat file.  
But you hadn't said it was **one** command. You threw stuff into the thread which I don't understand. It was just _text_ to me.

Then there is the path.  
Again, not really of concern, but since you now declared it......

In the node-red `exec` node you put the command (the FULL command with path declared).  
As I showed you in the node I posted.

That will execute the command.

What happens next is determined by you. Timing is going to be a bit difficult, but I think one of the outputs of the node tells you if the command was successful and you could use that to trigger the next part/stage.

But again I ask: What is Node-Red doing in the bigger scheme of things?

I don't know what `IIOT` is. _Combining algorithms and integration on a single platform_?  
Isn't that the job of a computer?

Ok. But you need to know the stages of flow of what happens when and to _whom_.  
Then determine how to handle that and get what you want.

It isn't going to be a 20 second trip to do it.

I have been using Node-Red for abut 1.5 years and I know **nothing** about it. All I do is try.

I'm not going to look at the last post re: "Can you explain the exe node".  
I think I have already and done more now.

And I have explained if it is one command it is redundant.

You enter the command you want to be executed.  
You can use the `msg.payload` as an option.

I am now struggling to construct words.

See what you make of this reply.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 March 2020 04:11 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/16 "2020-03-29T04:11:34Z")

</div>

When posting code, you need to use the `</>` button in the menu above.

![Screenshot from 2020-03-29 15-10-43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a60acfb4be1ef18f2905646d259ffac1fee7219.png)

---

<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:** [29 March 2020 06:47 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/17 "2020-03-29T06:47:16Z")

</div>

You should just be able to execute your command directly, using an exec node, there should be no need for a batch file.  
You might need to specify the full path to the program, but you might not, try it and see. If you are passing file names to the program then use the full path with forward slashes, not back slash. If you need to pass variable parameters you can pass them in msg.payload but get it working first be putting the full command and parameters in the exec node.  
Put debug nodes on all the exec node's outputs initially, in order to capture any errors.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 07:16 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/18 "2020-03-29T07:16:56Z")

</div>

This is what I get

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a45d99f1372e1acfa317490b51272d2c39e5a67d.png)

---

<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:** [29 March 2020 07:20 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/19 "2020-03-29T07:20:09Z")

</div>

You need to use the full path, eg;

```auto
c:/impl/impl -fact......

```

note; i don't know how this works on windows, ie. if it requires double backslashes or forwardslashes

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [29 March 2020 07:24 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/20 "2020-03-29T07:24:40Z")

</div>

I execute this in IMPL-Excutable (console) using the following command  
C:\IMPL\>impl -fact=C:\IMPL\HeatExchanger\MassBalancing =filter=quality -fork=secqpe\_y12m

---

<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:** [29 March 2020 07:26 UTC](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809/21 "2020-03-29T07:26:08Z")

</div>

I have never seen that before, but my suggestion is: specify the full path. Node-red does not know where `impl` is.

[Next page](https://discourse.nodered.org/t/execute-dos-command-in-node-red/23809.md?page=2)
