the following run in powershell 3.0 under standard console powershell ise , using font contains tested unicode codepoint.
the following c# program correctly prints ~ (so know can work):
static void main(string[] args) { console.writeline("\u2248"); } on sidenote when @ console.outputencoding claims codepage ibm850 can't true. weirder independent of set codepage of console (using chcp) output fine, .net has worry encoding (or calling special apis?)
now when try following java program end garbled output ( "h):
public static void main(string[] args) throws unsupportedencodingexception { system.out.println("\u2248"); } now because java looks @ system encoding , uses that, windows-1252, that's expected, following doesn't work:
public static void main(string[] args) throws unsupportedencodingexception { new printstream(system.out, true, "utf-16").println("\u2248"); } what can use utf-8 , call chcp 65001 beforehand. works , shows right glyph, but has bug characters repeated @ end of line: printing \u2248weird. results in ≈weird.d. not great either.
so encoding c# using write console, or more how can java correctly output unicode in powershell?
what encoding c# using write console
none, .net using win32 api writeconsolew write characters (well, utf-16 code units) directly. there no encode/decode-from-bytes step, console's code page irrelevant. (and yes, 850 expected code page western europe.)
other apps , languages including java using c standard library io functions deal in bytes, there's encode-decode stage involved , use console code page.
what can use utf-8 , call chcp 65001 beforehand. works , shows right glyph, has bug characters repeated
this part of set of long-standing bugs in windows command line support code page 65001. code page 65001 not viable way c-stdlib applications support unicode on console reason.
generally there no pure cross-platform way write command-line apps support unicode. have detect you're connected character-oriented console (rather byte-oriented pipe) , running on windows, , in case branch call win32 writeconsolew. example using jna.
Comments
Post a Comment