OK, this is not so simple. However, please read my comments to the question first.
First, you need to set a correct font for your console. Run the application with some pause (see the second code sample below) once, click "Properties" and change the font.
Now, you need to set the encoding for three things: in first application (to be executed as a child process), this is the console output encoding. In the parent-process application, you need to do the same if you want to see the result, you need to do the same, but you also need to set standard output encoding in
System.Diagnostics.ProcessStartInfo
. Also, if you use some input, you should need all three things in input.
On my system, all UTFs except UTF-8, throw an exception. Let it be: only one UTF is probably currently implemented (Windows 7 Pro, in my case).
First, let's see how can you write the application which simply outputs the Unicode text:
namespace WriteAndPresentUnicode {
using System;
class Program {
static void Main(string[] args) {
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Пишем по-русски...");
}
}
}
Now, let's see how to start it as a chile process with redirection of output:
namespace ReadUnicode {
using System;
using System.Diagnostics;
using System.IO;
class Program {
const string application = "WriteAndPresentUnicode.exe";
static void Main(string[] args) {
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(application);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
Console.InputEncoding = System.Text.Encoding.UTF8;
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine(myString);
Console.WriteLine("Press any key...");
Console.ReadKey(true);
}
}
}
That's it, tested.
—SA