开发者

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");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜