Is there any difference between attaching callbacks or event listeners for child process in nodejs. like –
const execute = require('child-process').exec;
const process = execute('ping -n 1 www.google.com'); // or ping -c 1 www.google.com for mac
process.stdout.on('data', data => {
console.log(data)
})
In the above code i am using event listener for the output and i am getting stdout data in windows but can’t get the output in macos. But if i use callback like –
const execute = require('child-process').exec;
execute('ping -c 1 www.google.com', (error, stdout, stderr) => {
console.log(stdout);
})
I am getting the output data in both windows and mac.. Is there any difference using callback or event listeners(both are asynchronous)?