lwsjs/local-web-server

Server has no output when executed by node exec()

brachkow opened this issue · 3 comments

When I run server from cli everything works as expected, but if I run it from node.js it doesn't output anything.

const { exec } = require('child_process');
exec(
  `ws --directory ./dist/ --spa index.html --port 1111`,
  (error, stdout, stderr) => {
    if (error) {
      console.log(`error: ${error.message}`);
      return;
    }
    if (stderr) {
      console.log(`stderr: ${stderr}`);
      return;
    }
    console.log(`stdout: ${stdout}`);
  },
);

@75lb but I want to use in combination with other cli tools

75lb commented

exec does not return the output until the process has ended - the ws process never ends (until manually stopped) as it's a server, so by design it must stay alive..

To capture the output of a running process, use spawn.

Closing, as this is not a bug with local-web-server.