title: How to execute the shell-script in NodeJS and wait for it to display and get in the stream?
body: <p>I have connection in hardware with console
  But it work's with commands:</p>
  
  <p><a href="https://i.stack.imgur.com/IisOA.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>I create omron.sh because I need to run it in a nodeJS</p>
  
  <pre><code>#!/bin/sh
  
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/splincode/Develop/omron/c++_modules/libomron/omron-build/lib/
  ~/Develop/omron/usr/local/bin/omron_790IT_test
  </code></pre>
  
  <p>But me need it's work in NodeJS and write to stream stdout, however, not work</p>
  
  <p>server.js:</p>
  
  <pre><code>let http = require('http'), 
      fs = require('fs'),
      url = require('url'),
      path = require('path');
  
  let server = new http.Server(); // EventEmitter
  
  server.listen(8000, '127.0.0.1');
  server.on("connection", () =&gt; console.log("connection"));
  server.on('request', (request, response) =&gt; {
  
      console.log('.', request.url)
  
      let userUrl = decodeURIComponent(url.parse(request.url).pathname);
      let loadFile = false;
  
      switch(userUrl) {
          case '/': 
              userUrl += 'index.html';
              loadFile = true;
          break;
  
          case '/omron':
  
              console.log('omron')
  
              var util=require('util')
              var exec=require('child_process').spawn('sh', ['omron.sh']);
  
              // not work
              exec.stdout.on('data', (data) =&gt; {
                console.log(`stdout: ${data}`);
                response.end(`${data}`);
              }); 
  
          break;
  
          default: 
              loadFile = true;
          break;
      };
  
  
      if (userUrl === '/') userUrl += 'index.html';
  
  
      if (loadFile) {
          let pathname = path.normalize(path.join(__dirname, userUrl));
          fs.readFile(pathname, (err, content) =&gt; {
              let mime = require('mime').lookup(pathname);
              response.setHeader('Content-Type', `${mime}; charset=utf-8`);
              response.end(content);
          });
      }
  
  
  });
  </code></pre>
  
  <p>However, not work it, I need to give the shell-script a response to the output stream, but how?</p>
  
  <p><a href="https://i.stack.imgur.com/S82Wl.png" rel="nofollow noreferrer">enter image description here</a></p>