I have a Swift program that writes information to stdoutwhile waiting \n(which completes execution). It requests input immediately after start-up and registers information 1 ~ 2 seconds after:
fetchAndLogDataInBackground(); // will print some data in ~1 sec
readLine();
I spawning / execFilewith the following:
const spawn = require('child_process').spawn;
const process = spawn('swift/main');
process.stdout.on('data', data => console.log(data.toString()));
setTimeout(() => {
process.stdin.write('\n');
}, 5000);
I expected to see the "live" logs, as I use on('data'), but they are processed only afterprocess.stdin.write('\n');
Is there a way to get live data?
PS: if I run the Swift program in terminal ( swift/main), it works as expected.
source
share