How to process variables into exec-node running a C-program

I hope I didn't miss any post or information which would resolve my issue, but I seem to be unable to find anything.
I'm quite new to Node-Red and Node.Js in general, just been able to run a few other things yet, which have been a lot easier to manage.

I want to run a C executable via the exec-node, input variables and get different variables back.
The program is basically a script deciding the appropriate output in regards to the input. These variables change each time the exec-node is run in a set interval.

My problem right now is the communication between the C-Code and Node-Red. I have compiled a basic "addOne"-program.
An Input Variable in Node-Red should be set to whatever number I want, the program adds 1 and outputs the result. For later implementation it is not necessary that the output is a different variable but it would be helpful.

I'm unable to set the variable in Node-Red or get the program to use any set variable and am a bit lost on what to search for after having found nothing that resolved my issue.

If I missed anything please let me know.

Does your C program accept/process command line arguments?

Not right now, but I would like to change that in the future.
Is the solution without command line arguments more complex?

It's easy(ish) to put the program pathname in the exec node and use msg.payload for command line argument[s] Of course each command line argument will be seen as a string.

Untitled 7

It gets more difficult if you are passing JSON or some special characters which have to be protected from being mangled by the shell.

Have you ever tyied Native Abstraction for Node.js
A math demo is here NAN

I have worked out the command line argument functionality in the meantime.
You were right, it made the input much easier, although I still have to test how easy that will be when working with 3-digit large arrays later on.


I have not heard of that yet.
Will look up what that is capable of.

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