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

**URL:** <https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562>\
**Category:** General\
**Tags:** exec\
**Created:** [14 March 2023 17:53 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562 "2023-03-14T17:53:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![textMARCer](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@textMARCer](https://discourse.nodered.org/u/textMARCer)\
**Post date:** [14 March 2023 17:53 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/1 "2023-03-14T17:53:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 March 2023 17:55 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/2 "2023-03-14T17:55:30Z")

</div>

Does your C program accept/process command line arguments?

---

<div class="post-metadata">

**Author:** ![textMARCer](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@textMARCer](https://discourse.nodered.org/u/textMARCer)\
**Post date:** [14 March 2023 18:06 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/3 "2023-03-14T18:06:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 March 2023 18:17 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/4 "2023-03-14T18:17:00Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c24b15b098ba9272ff0501b374b3a4c27f283c8.jpeg)

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

---

<div class="post-metadata">

**Author:** ![magicfire](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/magicfire/32/93420_2.png) [@magicfire](https://discourse.nodered.org/u/magicfire)\
**Post date:** [15 March 2023 05:12 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/5 "2023-03-15T05:12:42Z")

</div>

Have you ever tyied **Native Abstraction for Node.js**  
A math demo is here [NAN](https://mp.weixin.qq.com/s?__biz=MzAxMTE1NjQ0Mg==&mid=2448836744&idx=1&sn=3a7b0ad0290d46e3efb0e997754d3271&chksm=8f47863db8300f2b8583d859b44c2c62aef7530738e832654f9bc975cf75afeddf4947fc6065&token=555071057&lang=zh_CN#rd)

---

<div class="post-metadata">

**Author:** ![textMARCer](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@textMARCer](https://discourse.nodered.org/u/textMARCer)\
**Post date:** [15 March 2023 06:21 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/6 "2023-03-15T06:21:05Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![textMARCer](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@textMARCer](https://discourse.nodered.org/u/textMARCer)\
**Post date:** [15 March 2023 07:22 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/7 "2023-03-15T07:22:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 May 2023 07:23 UTC](https://discourse.nodered.org/t/how-to-process-variables-into-exec-node-running-a-c-program/76562/8 "2023-05-14T07:23:23Z")

</div>

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