const { spawn } = require("child_process");
const { chunksToLinesAsync, chomp } = require('@rauschma/stringio');
const file = require.resolve('./dummyData.py');
async function main() {
const ls = spawn("python" , [file]);
await echoStdout(ls.stdout);
async function echoStdout(readable) {
for await (const line of chunksToLinesAsync(readable)) {
console.log('LINE: '+chomp(line))
}
}
ls.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
ls.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
ls.on('error', (error) => {
console.log(`error: ${error.message}`);
});
ls.on("close", code => {
console.log(`child process exited with code ${code}`);
});
}
main();