Code:
var readline = require("readline")
var str;
var prompt = function (){
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.setPrompt ("> ", 2);
rl.on ("line", function (line){
str = line
this.close ();
});
rl.on ("close", function (){
process.stdout.write (str) <<<----- LINE 1
//console.log (str) <<<------------ LINE 2
//prompt (); <<<------------------- LINE 3
});
rl.on ("SIGINT", function (){
process.stdout.write ("\n");
process.exit ();
});
rl.prompt ();
};
prompt ();
If LINE 3 is commented it prints:
> msg
msg
If LINE 3 is not commented (infinite prompting), LINE 1 doesn't print the
message:
> msg
> msg2
> msg3
But now, uncomment LINE 2, the message is printed 2 times. It seems that a
call to console.log() enabled the stdout stream again:
> msg
msgmsg
> msg2
msg2msg2
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.