我正在运行一个控制台应用程序(myApp.exe),它将伪本地化(unicode)字符串输出到标准输出。如果我在常规命令提示符 (cmd.exe) 中运行它,则 unicode 数据会丢失。如果我在 unicode 命令提示符(cmd.exe /u)中运行它或将控制台的属性设置为“Lucida Console”,那么将保留 unicode 字符串。
我想在 C# 中运行这个应用程序并将 unicode 字符串重定向到一个局部变量中。我正在使用 RedirectStandardOutput = true 的 Process 对象,但 unicode 字符串总是丢失。
如何指定保留此 Unicode 信息?
private static int RunDISM(string Args, out string ConsoleOutput)
{
Process process = new Process();
process.StartInfo.FileName = "myApp.exe";
process.StartInfo.Arguments = Args;
try
{
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
process.Start();
process.WaitForExit(Int32.MaxValue);
}
catch (Exception e)
{
WEX.Logging.Interop.Log.Assert("Failure while starting or running process.\nERROR: " + e.Message);
ConsoleOutput = null;
return EXITCODE_ERROR;
}
ConsoleOutput = process.StandardOutput.ReadToEnd();
return process.ExitCode;
}