How to do proper Unicode and ANSI output redirection on cmd.exe?
Posted
by Sorin Sbarnea
on Stack Overflow
See other posts from Stack Overflow
or by Sorin Sbarnea
Published on 2010-04-24T20:56:02Z
Indexed on
2010/04/24
21:03 UTC
Read the original article
Hit count: 771
If you are doing automation on windows and you are redirecting the output of different commands (internal cmd.exe
or external, you'll discover that your log files contains combined Unicode and ANSI output (meaning that they are invalid and will not load well in viewers/editors).
Is it is possible to make cmd.exe work with UTF-8? This question is not about display, s about stdin/stdout/stderr redirection and Unicode.
I am looking for a solution that would allow you to:
- redirect the output of the internal commands to a file using UTF-8
- redirect output of external commands supporting Unicode to the files but encoded as UTF-8.
If it is impossible to obtain this kind of consistence using batch files, is there another way of solving this problem, like using python scripting for this? In this case, I would like to know if it is possible to do the Unicode detection alone (user using the scripting should not remember if the called tools will output Unicode or not, it will just expect to convert the output to UTF-8.
For simplicity we'll assume that if the tool output is not-Unicode it will be considered as UTF-8 (no codepage conversion).
© Stack Overflow or respective owner