Skip to content

Instantly share code, notes, and snippets.

@thekid
Created September 15, 2013 15:10
Show Gist options
  • Select an option

  • Save thekid/6571614 to your computer and use it in GitHub Desktop.

Select an option

Save thekid/6571614 to your computer and use it in GitHub Desktop.
Output UTF-8 to Windows Shell
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int wmain(int argc, wchar_t** argv) {
int i;
_setmode(_fileno(stdout), _O_U8TEXT);
fwprintf(stdout, L"args [%d]{", argc);
for (i = 0; i < argc; i++) {
fwprintf(stdout, L"(%d)'%ls', ", wcslen(argv[i]), argv[i]);
}
fwprintf(stdout, L"}\n");
return 0;
}
@thekid
Copy link
Author

thekid commented Sep 15, 2013

Cygwin mintty w/ encoding = utf-8:

$ ./args.exe "Russland" Россия
args [3]{(35)'F:\cygwin\home\Timm Friebe\args.exe', (8)'Russland', (6)'Россия', }

Windows "cmd.exe" regardless of current codepage(!)

C:\> args.exe "Russland" Россия
args [3]{(8)'args.exe', (8)'Russland', (6)'Россия', }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment