-
Notifications
You must be signed in to change notification settings - Fork 7.3k
readline treats \n\r as two lines, passes content through #3305
Comments
\n\r is not an end-of-line convention on any platform we support. Try \r\n. |
Node 0.6.x detects if it's user input looking only to stdout, not stdin. So In node 0.7.x it seems that you should manually set isterminal flag like that: #!/usr/bin/node
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout, undefined,
process.stdin.isTTY && process.stdout.isTTY),
prefix=""
rl.on('line', function(line) {
console.log("line is [" + line + "]")
}).on('close', function() {
process.exit(0);
}); PS: well yeah... there are a few bugs around there :) // @TooTallNate: fixed |
any ideas about the '\r\n' part?
|
This line in |
Make lines ending \r\n emit one 'line' event, not two (where the second one is an empty string). This adds a new keypress name: 'return' (as in: 'carriage return'). Fixes nodejs#3305.
Thanks for looking into this. If I understand the pull request correctly, it "disarms" Meanwhile, workarounds for in-production node versions look complicated, especially as they do not have the new Streams yet (I was thinking of replacing |
Node does not support pre-OS X Macintosh systems. (Neither do most Mac OS X programs these days.) I think we're ok there. |
Fixed in 9bd9c54. |
The problem here is that the repl is busted by 9bd9c54. (I guess we all ran I think when you're reading a stream, |
This is really two bugs, but they are in the same bit of code.
When I write "cat" with nodejs, it sends the input to the stdio twice. It also treats \n\r as two lines. This only happens when piping data through the program, at the command line things work.
Here is some sample code:
!/usr/bin/node
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout),
prefix=""
rl.on('line', function(line) {
console.log("line is [" + line + "]")
}).on('close', function() {
process.exit(0);
});
At the command line, things work:
but when I pipe through a file with Unix style return it does the following:
echo -e "first line\nsecond line" | ./sample.js
first line <===== extra
line is [first line]
second line <===== extra
line is [second line]
and when I pipe through something with the \r added, it does the following:
echo -e -n "first line\n\rsecond line\n\r" | ./sample.js
first line <===== extra
line is [first line]
<===== extra
line is [] <===== extra
second line <===== extra
line is [second line]
<===== extra
line is [] <===== extra
This makes it kind of, um, impossible to use node.js as a command line tool, which is unfortunate, because we have to process pages of JSON data.
I'd be happy to personally debug this and get you guys a patch, if you think you might use it.
The text was updated successfully, but these errors were encountered: