The /u
option controls the behaviour of the command interpreter, and has nothing to do with the console. This question, and indeed several of the comments to it, are making the classic mistake, made so many times before, of conflating a console with a command interpreter that just happens to be one of the processes using that console. A command interpreter is not a console. Options to make a command interpreter (or indeed any other program) write its output in certain ways have nothing whatsoever to do with the console to which that output may, or may not, be directed.
Indeed, these options aren't even console-related. The /U
and /A
options to CMD
flip an internal toggle within the command interpreter itself, that is checked by built-in commands such as DIR
before they write to pipes and to files. The state of the toggle determines how they choose to write their output. One can even see this option in the source code for the Reactos CMD
. The toggle is bUnicodeOutput
and it's checked by the ConWrite()
function.
And this of course indicates how one goes about doing this in one's own program to achieve the same effect. One gives one's program /U
and /A
(or otherwise named) options, flips a toggle accordingly, and modifies the writing behaviour of one's program when it discovers that it is writing to pipe or file. In other words: One does exactly what CMD
does. And the user runs one's program passing it the /U
and /A
options, just like they do when they use CMD
.
In yet other words: An example of this mechanism already exists. Just copy it.