# Struggling with exec node

**URL:** <https://discourse.nodered.org/t/struggling-with-exec-node/43080>\
**Category:** General\
**Created:** [23 March 2021 11:57 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080 "2021-03-23T11:57:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter\_a](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@peter\_a](https://discourse.nodered.org/u/peter_a)\
**Post date:** [23 March 2021 11:57 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/1 "2021-03-23T11:57:37Z")

</div>

I've been struggling to use the exec node to run a command that will work in a standard linux cli. The command sends a request to a thermostat in my home, and returns a JSON object with the current status of the thermostat. The command is:

`echo -e '{"GET_SYSTEM": 0}\0\r' | nc 192.168.1.20 4242`

It works perfectly in the Raspberry Pi terminal, but when I've tried using it in the exec node, I don't get the result I'd expect:

1 - If I add the command, as written above, to the "Command" field of the exec node, I get no message on the stdout, stderr or return code outputs of the node.

2 - I've tried changing to spawn mode, instead of exec node, and then I get a raw data buffer output, which I can't comprehend.

3 - I've tried "injecting" the command to the exec node as well, and this gives the same results.

Any pointers? Is there something obvious I'm missing?

---

<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:** [23 March 2021 12:04 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/2 "2021-03-23T12:04:26Z")

</div>

can you show us the debug output of the spawn command - The node will try to parse it to a string - but if there are any non-ascii characters in there it will drop back to a buffer.

---

<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:** [23 March 2021 12:05 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/3 "2021-03-23T12:05:01Z")

</div>

so you are actually running multiple commands because of the Piping. Try this, put the commands in a script then execute the script.

---

<div class="post-metadata">

**Author:** ![peter\_a](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@peter\_a](https://discourse.nodered.org/u/peter_a)\
**Post date:** [23 March 2021 12:07 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/4 "2021-03-23T12:07:42Z")

</div>

Hi @dceejay. Output using spawn mode (using the "copy value" button in the debug panel) looks like:

`[39,123,34,71,69,84,95,83,89,83,84,69,77,34,58,32,48,125,0,13,39,32,124,32,110,99,32,49,57,50,46,49,54,56,46,52,46,50,52,48,32,52,50,52,50,10]`

---

<div class="post-metadata">

**Author:** ![peter\_a](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@peter\_a](https://discourse.nodered.org/u/peter_a)\
**Post date:** [23 March 2021 12:08 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/5 "2021-03-23T12:08:20Z")

</div>

Hi @zenofmud. Do you mean, create a script file on the local filesystem, and trigger that from within node red?

---

<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:** [23 March 2021 12:12 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/6 "2021-03-23T12:12:37Z")

</div>

> [@peter\_a](#):
>
> [39,123,34,71,69,84,95,83,89,83,84,69,77,34,58,32,48,125,0,13,39,32,124,32,110,99,32,49,57,50,46,49,54,56,46,52,46,50,52,48,32,52,50,52,50,10]

that's just the command echo'd back 🙂

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

but yeah why not try the tcp request node as that seems to be what you are doing... just sending a tcp command to port 4242

---

<div class="post-metadata">

**Author:** ![peter\_a](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@peter\_a](https://discourse.nodered.org/u/peter_a)\
**Post date:** [23 March 2021 12:43 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/7 "2021-03-23T12:43:28Z")

</div>

Solved! One of those things I'm embarrassed I didn't spot. The netcat command wasn't automatically closing the server connection after receiving data. Adding a short timeout flag to the end of the command sorted everything. 🙂

---

<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:** [6 April 2021 12:44 UTC](https://discourse.nodered.org/t/struggling-with-exec-node/43080/8 "2021-04-06T12:44:04Z")

</div>

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