# Exec node spawn mode

**URL:** <https://discourse.nodered.org/t/exec-node-spawn-mode/102306>\
**Category:** General\
**Created:** [1 December 2026 21:42 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306 "2026-12-01T21:42:59Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [1 December 2026 21:42 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/1 "2026-12-01T21:42:59Z")

</div>

According to the docs, exec

> Optionally can use `spawn` instead, which returns the output from stdout and stderr as the command runs, usually one line at a time

Why "usually", and is there a simple way to enforce one message per line?

Will it ever emit less than a full line, ie break the executed program's output at some point besides a new line?

I know I can use a split node to get back to one message per line, it seems inelegant.

---

<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:** [1 December 2026 23:42 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/2 "2026-12-01T23:42:21Z")

</div>

It depends what the called program does and indeed sometimes how it is interpreted. C programs can flush or not flush, python tends not to unless you specify -u etc. so 🤷

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [1 December 2026 23:51 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/3 "2026-12-01T23:51:58Z")

</div>

When I do pure JS programming, and need to spawn a sub-process and listen to its messages, I import the package`node:readline`, create a reader and listen to `.on('line',...` notifications, which are buffered & returned one line at a time. It works great.  
Unless there is a specialized node which does this (of which I am not aware), you may try importing this package into a function node implementing this inside it.

---

<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:** [2 December 2026 00:36 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/4 "2026-12-02T00:36:02Z")

</div>

In this instance the executed command is `tail -n 0 -F /var/log/mosquitto/mosquitto.log` to detect mqtt droputs.  
It sometimes emits multiple lines with the same timestamp, eg

```auto
1796170065: New connection from 192.168.1.100:52293 on port 1883.
1796170065: Client DVES_123456 already connected, closing old connection.
1796170065: New client connected from 192.168.1.100:52293 as DVES_123456 (p2, c1, k30, u'admin').

```

Generally these do indeed arrive in Node-red as discrete messages, but sometimes it's just one message including new line characters.

Of course I can't reliably reproduce it/ demonstrate.

Is it possible that three messages arriving at the same instant somehow confuses the exec node so it conflates them?

@omrid Thanks for the suggestion, I'm actually more comfortable using an exec node and OS commands.  
I would have thought this might be something the standard nodes could do.  
The read file node can read the entire file but not track new lines.  
There is a node-red-contrib-tail-file but it has been a beta release for 9 years so I'm not going to bother with it.

Also in this case things are complicated by Node-red not being able to read the log file without sudo.

@dceejay Ought the exec node have the ability to restart a failed command? Sort of a respawn mode? (Only matters for relatively long running commands and so probably in spawn mode)

There is a work-around in Linux: a systemd service, but it's nice for processes needed by Node-red to be specified within NR and to be killed when NR stops.

---

<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:** [2 December 2026 09:50 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/5 "2026-12-02T09:50:34Z")

</div>

> [@jbudd](#):
>
> Is it possible that three messages arriving at the same instant somehow confuses the exec node so it conflates them?

I think the exec node is just passing on the buffers that tail passes it via stdout, the timestamps are added by mosquitto. If tail chooses to send multiple lines in one buffer, or split it in the middle of a line, then there is not much you can do other than reconstruct the lines yourself.

By the way, if you are working much with mosquitto logs then you can put this in your mosquitto conf file to get it to add meaningful timestamps.

```auto
# human readable timestamps in log
log_timestamp true
log_timestamp_format %Y-%m-%d %H:%M:%S

```

---

<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:** [2 December 2026 10:08 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/6 "2026-12-02T10:08:01Z")

</div>

I think tail -F is unbuffered. Might be wrong. So that's one message per line.

Yes the timestamp comes from mosquitto.  
The three messages I showed above have the same timestamp, though it's resolution is seconds, a long time in computing.  
They do seem to be emitted essentially simultaneously.

The problem is that multiple output lines from tail occasionally get conflated by the exec node.

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [2 December 2026 10:41 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/7 "2026-12-02T10:41:14Z")

</div>

> [@jbudd](#):
>
> @omrid Thanks for the suggestion, I'm actually more comfortable using an exec node and OS commands.

I'm talking about using an exec node, and feeding its raw stdout output stream into a function node in which you can then parse it and construct messages as needed.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 December 2026 11:41 UTC](https://discourse.nodered.org/t/exec-node-spawn-mode/102306/8 "2026-12-02T11:41:28Z")

</div>

> [@jbudd](#):
>
> Also in this case things are complicated by Node-red not being able to read the log file without sudo.

That is, potentially fixable of course - at the OS level. Create a new group that has read-only access to the logs and add the node-red and system admin users to the group.
