I'm starting a CLI process with node.js on Windows that outputs data to stdout which I capture on "data"
const { spawn } = require('child_process');
const process = spawn(path);
process.stdout.on("data", (data) => {
const message = data.toString("utf16le").replace(/\0/g, "");
console.log(message);
});
Then problem is that I only get data when a new line has been emitted. Sometimes multiple lines at the same time (which is fine), but always with a new line at the end. Sometimes the application emits the last line without a new line, so I don't get that line until the process continues with the next output.
Is it possible to read stream data without new lines?