reading from stdin in nodejs forcibly converts \r\n to \n
In a script i am trying to make, nodejs reads from stdin, but forcefully converts all \r\n to \n. This causes another of my script to produce improper results.
Is there a way i can prevent that from happening?
This is the code I am using to read fr开发者_运维知识库om stdin.
process.stdin.resume();
process.stdin.setEncoding('ascii');
process.stdin.on('data', function(chunk){
data += chunk;
})
process.stdin.on('end', function(){
console.log(JSON.stringify(data));
});
You can use this :
process.stdin.on('data', function(chunk){
data += chunk.replace(/\r\n/g,"\n");
});
精彩评论