Execute dos command in node-red

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.

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.

1 Like

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.

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

 <//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.

(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.

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

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 -

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

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:

[{"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":[[],[],[]]}]
1 Like

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.

.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.

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

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

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:

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

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

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?

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.

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?

[{"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":[[],[],[]]}]

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.

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.

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

Screenshot from 2020-03-29 15-10-43

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.

This is what I get

You need to use the full path, eg;

c:/impl/impl -fact......

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

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

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