# Exec node send an output payload on more than one message

**URL:** https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590
**Category:** General
**Tags:** exec
**Created:** [2 February 2023 08:09 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590 "2023-02-02T08:09:04Z")
**Posts on this page:** 15
**Page:** 2

<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: [3 February 2023 07:30 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/21 "2023-02-03T07:30:02Z")

</div>

You haven't included the flush command.

---

<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: [3 February 2023 09:18 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/22 "2023-02-03T09:18:27Z")

</div>

It does seem that something is badly broken between the exec node and Python 2.7.  
I tested on a Pi running RPiOS Buster. but the OP says the same happens on Windows.

Flushing stdout makes no difference, nor does substantially reducing the size of the output.

> [@Lupin\_III](#):
>
> I have the same problem on a raspberry with raspbian

> [@Lupin\_III](#):
>
> Unfortunately yes, I have to use python language

I don't see the same problem if I change the exec node to call python3. (As @Colin says, the script #! line is ignored.)  
@Lupin_III if you are on a Raspberry Pi , why do you have to use python 2?

---

<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: [3 February 2023 09:41 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/23 "2023-02-03T09:41:54Z")

</div>

Did you add the flush and remove the -u? That is working perfectly for me on a pi running Buster.

---

<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: [3 February 2023 09:57 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/24 "2023-02-03T09:57:26Z")

</div>

> [@Colin](#):
>
> Did you add the flush

```auto
import time
import sys
while True:

    a=[402.17, 10.16, 17.2, 3482.43, 138.55, 27.76, 27.64]
    print (a)
    sys.stdout.flush()
    time.sleep(5)

```

> [@Colin](#):
>
> and remove the -u?

```auto
python /home/pi/try

```

With this short output it only manifests as splitting the carriage return onto a seperate message sometimes

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/227f54d760643f2984fec4a264d049fee2507044.jpeg)

---

<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: [3 February 2023 10:05 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/25 "2023-02-03T10:05:08Z")

</div>

That is odd. What does `python --version` show?

---

<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: [3 February 2023 10:08 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/26 "2023-02-03T10:08:17Z")

</div>

python 2.7.16

But on that Pi, python3 is 3.7.3 and imho python3 should _always_ be specified  
On newly installed RpiOS 64 bit, python --version gives 3.9.2

---

<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: [3 February 2023 10:25 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/27 "2023-02-03T10:25:31Z")

</div>

I agree with you about python 3. We wait to hear why python 2 must be used here.  
I have the same version of python 2, the same OS, but for me, with the flush and without -u it works perfectly. Strange.

---

<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: [3 February 2023 10:26 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/28 "2023-02-03T10:26:43Z")

</div>

@jbudd are you using node-red 3.0.2? Which version of nodejs?

---

<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: [3 February 2023 10:45 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/29 "2023-02-03T10:45:07Z")

</div>

Yes 3.0.2, node -v gives 16.19.0

---

<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: [3 February 2023 10:46 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/30 "2023-02-03T10:46:42Z")

</div>

> [@jbudd](#):
>
> npm 16.19.0

I assume you mean node 16.19.0, which is the same as I am, so it isn't that.

---

<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: [3 February 2023 12:48 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/31 "2023-02-03T12:48:11Z")

</div>

Don't forget that at the end of the day it is all running on a multi-tasking OS - so the process can yield to another and decide to send the buffer when it needs to - it doesn't have to wait for a flush.  
Worst case you will have to rebuild the lines once they arrive in Node-RED. I "think" - (as in not done it for a while) that the split node does actually buffer things up until it sees the split character - so that may help (assuming there is always a charater to reliably split on.

---

<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: [3 February 2023 13:14 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/32 "2023-02-03T13:14:54Z")

</div>

It does seem more reliable for a short message at least if you flush before and after printing.  
Not tried with Colin's long message.

---

<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: [3 February 2023 13:43 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/33 "2023-02-03T13:43:32Z")

</div>

> [@dceejay](#):
>
> the split node does actually buffer things up until it sees the split character

Magic, I didn't realise it would do that.  
@Lupin_III you can go back to your original flow, without the flush and with `-u`, and feed that into a Split node configured like this

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

That will then handle the stream of messages, join them, and then split on the newline.

---

<div class="post-metadata">

### Author: ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)
#### Post date: [3 February 2023 14:01 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/34 "2023-02-03T14:01:25Z")

</div>

Thanks to all. For the very nexrt days I won't be able to make other test.  
Any way, just a couple of quick update:

- Unfortunatly at the moment I have to use python 2 because the script needs some important adjustment in order to make it working on python 3. At the moment these changing are not feasable and the script is quite complex.
- The best workaround I've found is to print iin python as json, like

```auto
    a=[-402.17, 10.16, 17.2, 3482.43, ..........]
    mydata = {
        "details" : a
    }
    print(json.dumps(mydata))

```

in this way, but only putting -u paramiter within the exec node, the message is always sent in a unique msg payload.Sometimes a special character for a new line is happened at the end (not always). But it is something easy enough to manage.

---

<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: [21 February 2023 01:59 UTC](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590/35 "2023-02-21T01:59:12Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/exec-node-send-an-output-payload-on-more-than-one-message/74590.md?page=1)
