printargv.js:
console.log(Buffer.byteLength(process.argv[2]));
In cmd.exe (with chcp=65001,font=’Lucida Console’), I ran:
node printargv.js Ā
(Note: unicode code point of Ā is U+0100.) The script outputted:
1
I expected the script to print a number greater than 1 but it doesn’t. Does anyone know why?
edit:
i think that node ‘parses’ initial arguments incorrectly for cmd.exe after i tried the below code:
var i = require('readline').createInterface(process.stdin,process.stdout);
i.question('char: ', function(c){
console.log( Buffer.byteLength(c) );
i.close();
process.stdin.destroy();
});
the output is 2
Your program is not receiving the
Ā, it’s receiving anAinstead. I used this program to test:On Ubuntu using UTF-8 in the console, I got:
…which is correct.
On Windows 7 using
chcp 65001and Lucida Console, I got:Note that the
Ābecame anAat some point along the way.As I said in my comment on the question, I can only assume there’s some issue with Lucida Console, or cmd.exe’s handling of UTF-8, or perhaps
node.exe‘s handling of Unicode from the console on Windows (I used the pre-built 0.5.7 version).Update: This might be something to take up with the NodeJS folks, since Windows appears to get it right on its own. If I put this code in a
test.vbsfile:I get a correct result:
…suggesting that the terminal is passing the argument correctly to the program. So it could be an issue with the Windows
node.exebuild.