Wrong encoding in DataReceivedEventArgs
- by user2102508
I start cmd.exe process and redirect stdin to pass script to it and redirect stdout and stderr to read cmd's output. Here is the code of my DataReceivedEventHandler:
(o, a) => {
if(!String.IsNullOrEmpty(a.Data)) {
bw.Write(a.Data.ToUTF8());
bw.Write((byte)'\n');
}
}
In the code bw is instance of BinaryWriter, ToUTF8 is string extension method, that converts a string to UTF8 encoded byte array. When I use this code in a separate process it works well, however when I use this code as a shared library inside some other process a.Data doesn't contain valid localized characters (like russian characters for example).
So how should I convert characters? How to get cmd's OEM encoding? Why does the code works well in a separate process and doesn't work as a shared library inside some other process?