unicodecommand-lineinputwindows-console

How can I use Unicode characters on the Windows command line?


We have a project in Team Foundation Server (TFS) that has a non-English character (š) in it. When trying to script a few build-related things, we've stumbled upon a problem; we can't pass the š letter to the command-line tools. The command prompt or what not else messes it up, and the tf.exe utility can't find the specified project.

I've tried different formats for the .bat file (ANSI, UTF-8 with and without BOM) as well as scripting it in JavaScript (which is Unicode inherently), but no luck. How do I execute a program and pass it a Unicode command line?


Solution

  • My background: I have used Unicode input/output in a console for years (and do it a lot daily. Moreover, I develop support tools for exactly this task). There are very few problems, as far as you understand the following facts/limitations:

    The details

    Practical considerations

    One should also keep in mind that the “alternative, ‘more capable’ consoles” for Windows are not consoles at all. They do not support Console-I/O APIs, so the programs which rely on these APIs to work would not function. (The programs which use only “File-I/O APIs to the console file handles” would work fine, though.)

    One example of such non-console is a part of Microsoft’s PowerShell. I do not use it; to experiment, press and release the Windows key, and then type powershell.


    (On the other hand, there are programs such as ConEmu or ANSICON which try to do more: they “attempt” to intercept the Console-I/O APIs to make “true console applications” work too. This definitely works for toy example programs; in real life, this may or may not solve your particular problems. Experiment.)

    Summary

    Update: Initially, for a bug in cp65001, I was mixing up Kernel and CRTL layers (Update 2: and Windows user-mode API!). Also: Windows 8 fixes one half of this bug; I clarified the section about “better console” application, and added a reference to how Python does it.