<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Multiline text output inside exec block is displayed as 1 line]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have a very simple module that executes a linux “cat” command on a file every N seconds.<br />
It works as expected except the line breaks in the file are ignored. All lines are displayed as 1 single line.</p>
<p dir="auto">This is how I call the cat command inside node_helper.js:<br />
var NodeHelper = require(‘node_helper’);<br />
const exec = require(‘child_process’).exec;</p>
<p dir="auto">module.exports = NodeHelper.create({</p>
<pre><code>readfile: function () {
exec("cat /path/to/file/out.txt", (error, stdout, stderr) =&gt; {
	if (error) {
		console.error(`exec error: ${error}`);
		return;
	}
    	this.sendSocketNotification('UPDATE', stdout);
});
},

socketNotificationReceived: function(notification, payload) {
	if (notification === 'TICK') {
	this.readfile();
}
},
</code></pre>
<p dir="auto">});</p>
<p dir="auto">Inside the module class, this is how I handle the update coming from socketNotificationReceived:</p>
<pre><code>	socketNotificationReceived: function(notification, payload) {
	    if (notification === 'UPDATE') {
	this.config.text = payload;
	this.updateDom()
    }
	},
</code></pre>
<p dir="auto">The reason I took this approach is I have absolutely no JS experience whatsoever, so I’m preparing the text file using a bash script and then use my MMM to display the result. (I moved the processing outside JS domain)</p>
<p dir="auto">Is it possible to use “cat” and display multiline?<br />
Or should I use a completely different approach e.g. reading the file inside JS line by line and displaying the result. If this is the correct approach then please point me to some examples.</p>
<p dir="auto">Thanks in advance</p>
]]></description><link>https://forum.magicmirror.builders/topic/13501/multiline-text-output-inside-exec-block-is-displayed-as-1-line</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 01:16:32 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/13501.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Aug 2020 11:19:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multiline text output inside exec block is displayed as 1 line on Fri, 21 Aug 2020 23:11:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/autonomus" aria-label="Profile: autonomus">@<bdi>autonomus</bdi></a> cool. glad u got it working</p>
]]></description><link>https://forum.magicmirror.builders/post/80546</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/80546</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 21 Aug 2020 23:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to Multiline text output inside exec block is displayed as 1 line on Fri, 21 Aug 2020 23:11:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> Thanks for the help!<br />
You made me realise that I need to return HTML syntax. This works as expected:<br />
line 1 text &lt; br&gt;<br />
line 2 text &lt; br&gt;<br />
…</p>
<p dir="auto">For reference, I was building a table for my data.<br />
Instead of multi lines with tabs, I switched to HTML tables.</p>
]]></description><link>https://forum.magicmirror.builders/post/80545</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/80545</guid><dc:creator><![CDATA[autonomus]]></dc:creator><pubDate>Fri, 21 Aug 2020 23:11:03 GMT</pubDate></item><item><title><![CDATA[Reply to Multiline text output inside exec block is displayed as 1 line on Fri, 21 Aug 2020 12:16:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/autonomus" aria-label="Profile: autonomus">@<bdi>autonomus</bdi></a> when cat returns, u have a big blob of text, with a line feed ‘\n’ between each ‘line’</p>
<p dir="auto">web doesn’t understand ‘\n’</p>
<p dir="auto">so you have to change those to ‘&lt; br&gt;’<br />
line break. note there is a space between &lt; and br. this forum hides the content if that space is not provided</p>
]]></description><link>https://forum.magicmirror.builders/post/80473</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/80473</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 21 Aug 2020 12:16:34 GMT</pubDate></item></channel></rss>