title: Stdout from spawnSync to express-handlebars
body: <p>Newbie with Node so please bear with me.
  Also I know this question has been asked before but I haven't figured out how to use it in my case so again, please do try to help.</p>
  <p>What I'm trying to do -
  Trying to get the images for a specific docker container in list format using express-handlebars.</p>
  <p>Code -</p>
  <pre><code>app.get('/restore/:userid', async (req,res) =&gt; {
    let userid = req.params.userid
    let userData = await Users.findById(userid, async function(err, data) {
      let site = await data.docker.site.slice(8)
      let backupsRun = await spawnSync('sh', ['-c', `echo redhat237 | sudo -S docker images | grep ${site} | awk '{print $2}'`], {encoding: 'utf-8'})
      let backupsStdout = await backupsRun.stdout
      if (backupsRun.status != 0) {var getBackups = new Error(&quot;Cannot fetch Backups&quot;)}
      let backupsStdoutDecoded = await unescape(encodeURIComponent(backupsStdout))
      let backupsArr = await backupsStdoutDecoded.split(&quot;\n&quot;)
      /*for (var i = 0; i &lt; backupsArr.length; i++) {
        var backups = await backupsArr[i].value
      }*/
      let backups = backupsArr
      try {
        console.log(backups + ' Try Block')
        await res.render('restore', {
          helpers: {
            userid: function () {return req.params.userid},
            site: site,
            backups: backups
          }
        })
      } catch (e) {
        if (e.getBackups) {
          res.send(e.getBackups)
        } else {
          res.send(e)
        }
      }
    })
  }) //close restore get
  </code></pre>
  <p>I can see the output in console.log but it reads as 1 line with seemingly 1 index.</p>
  <pre><code>test.test.org-12-7-2021T12_13,test.test.org-12-07-21T12_10,test.test.org12-07-21T12_10,test.test.org, Try Block
  </code></pre>
  <p>My handlebars page -</p>
  <pre><code>&lt;h1&gt;Restore for {{site}} - &lt;/h1&gt;
  &lt;ul&gt;
    {{#each backups}}
    &lt;li&gt;&lt;p&gt;{{this}}&lt;/p&gt;&lt;/li&gt;
    {{else}}
    &lt;h3&gt;ERROR - No Backups or we couldn't retrieve your backups&lt;/h3&gt;
    {{/each}}
  &lt;/ul&gt;
  &lt;div&gt;
    {{backups}} - Backups array in div
  &lt;/div&gt;
  </code></pre>
  <p>The strange thing is I can see the output in the div section which I had added for debugging, however I can't get the #each block to iterate.</p>
  <p>From what I can understand from the following situation is that while split() is supposed to return an array of substrings for some reason that doesn't seem to be happening.</p>
  <p>I even went and tried join() and toString() but it was the same result.
  If I uncomment the for loop and run it with .value it returns &quot;undefined&quot; in the console.log.</p>
  <p>If someone could please point out my mistake/s and help me with it, I'd really appreciate it.</p>