Skip to content

Flush stdout in mqtt-sub #446

@roleoroleo

Description

@roleoroleo

Hi.
I'm using mqtt-sub inside a shell script like this:

while :; do
mqtt-sub -h 192.168.100.100 -p 1883 -n mytopic | while read -r SUBSCRIBED; do
    ...
done

and I noticed that read is not able to get the standard output properly.
A fflush after printf fixes the problem.
Is it possible to add it in the main source?
Here a little patch:

diff -Naur wolfMQTT-1.20.0.ori/examples/pub-sub/mqtt-sub.c wolfMQTT-1.20.0/examples/pub-sub/mqtt-sub.c
--- wolfMQTT-1.20.0.ori/examples/pub-sub/mqtt-sub.c<--->2025-05-01 22:34:47.000000000 +0200
+++ wolfMQTT-1.20.0/examples/pub-sub/mqtt-sub.c>2025-11-25 10:54:53.064091696 +0100
@@ -96,6 +96,7 @@
     }
     else {
         PRINTF("%s", buf);
+        fflush(stdout);
     }
.
     #ifdef WOLFMQTT_V5

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions