0
const spawn = require('child_process').spawn;

function main() {
    ls = spawn('dir', {shell: true});
    ls.stdout.on('data', data => console.log('DATA RECEIVED'));
    ls.on('exit', code => console.log('EXITED'));
}

main();

This runs on Windows, and the result is

DATA RECEIVED
EXITED
DATA RECEIVED

Why is EXITED printed out before the last line? Is there any way safe to check whether all the data is received or not?

0 Answers0