Windows console is broken

Vladimir Panteleev thecybershadow at gmail.com
Wed Jan 30 19:26:37 PST 2008


On Thu, 31 Jan 2008 01:30:48 +0200, Sergey Gromov <snake.scaly at gmail.com> wrote:

> Sorry to mention it again, but it is.
>
> If a command-line argument to a D program contains a non-ascii character, that argument doesn't get into main().  This happens even if console code page is 65001.  This is most annoying because it cannot be worked around.

If I understood your problem correctly, here's a workaround:

import std.windows.charset, std.string;
import std.file;

void main(char[][] args)
{
        // convert from MBS (Windows ANSI encoding) to UTF-8
        foreach(ref arg;args)
                arg = fromMBSz(toStringz(arg));

        write(args[1], "Hello international world!");
}

C:\Temp\d\encoding> dmd example.d
C:\Soft\dmd\bin\..\..\dm\bin\link.exe example,,,user32+kernel32/noi;

C:\Temp\d\encoding> example "Привет, мультиязыковый мир!.txt"

C:\Temp\d\encoding> dir
 Volume in drive C is SYSTEM
 Volume Serial Number is C801-8D10

 Directory of C:\Temp\d\encoding

31.01.2008  05:01    <DIR>          .
31.01.2008  05:01    <DIR>          ..
31.01.2008  04:57               257 example.d
31.01.2008  04:58           100 892 example.exe
31.01.2008  04:58             2 390 example.map
31.01.2008  04:58               983 example.obj
31.01.2008  04:58                26 Привет, мультиязыковый мир!.txt
               5 File(s)        104 548 bytes
               2 Dir(s)   3 325 255 680 bytes free


-- 
Best regards,
 Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list