I know the solution is very simple, but it's an hour I'm banging my head.
In Windows 10, if i launch the command "dir", i got this result:
Il volume nell'unità D non ha etichetta.
in Node js i try to exec the dir command in this way:
var child = exec('dir', {'encoding': 'UTF-8'}, (err, stdout, stderr) => {
console.log(stdout);
});
and i got this result: Il volume nell'unit� C non ha etichetta.
Ah, damned accented letter!
I tried using UTF-16 and then, convert to string:
var child = exec('dir', {'encoding': 'UTF-16'}, (err, stdout, stderr) => {
let b: Buffer = stdout;
let o: string;
o = stdout.toString('UTF-8');
console.log(o);
});
I get the same cursed result:
"Il volume nell'unit� C non ha etichetta."
Can you help me to solve this rebus? What am I doing wrong?
It almost seems that the exec command does not accept UTF-8 encoding In fact, if I run this script to force conversion from UTF-8 to string:
var child = exec(j.cmd, {'encoding': 'UTF-8'}, (err, stdout, stderr) => {
var utf8 = require('utf8');
var o: string = utf8.decode(stdout)
console.log(o);
});
i got this error:
..\node_modules\utf8\utf8.js:194 throw Error('Invalid UTF-8 detected');
Any idea?