Reputation: 113
Take the following snippet:
try {
fs = require('fs');
fs.writeSync(0, 'Trying now...');
fs.writeSync(0, 'worked!\r');
}
catch(error){}
As is, it will not output to the console, however
try {
fs = require('fs');
fs.writeSync(0, 'Trying now...');
fs.writeSync(0, 'worked!\r');
console.log();
}
catch(error){}
Will output "Trying now... worked!" to the console. What exactly is going on here?
Upvotes: 1
Views: 311
Reputation: 665456
You're writing to the file descriptor but are not flushing it. Writing a line break (\n
instead of \r
) does lead to stdout flushing its buffer, as well as a console.log()
call that forces it.
Upvotes: 3