【发布时间】:2011-02-20 18:59:10
【问题描述】:
我遇到了Process.StandartInput 编码的问题。我在我的 Windows 窗体应用程序中使用了一些进程,但输入应该是 UTF-8。 Process.StandardInput.Encoding 是只读的,所以我不能将它设置为 UTF-8,它会获取 Windows 默认编码,这会恶化在 UTF-8 中很好的本机字符。程序中使用了两个进程:一个将输出写入文件,另一个读取。因为我可以将输出编码设置为 UTF-8,所以该部分工作正常,但回读是我遇到问题的部分。我将包括我使用该过程的部分。
ProcessStartInfo info = new ProcessStartInfo("mysql");
info.RedirectStandardInput = true;
info.RedirectStandardOutput = false;
info.Arguments = mysqldumpstring;
info.UseShellExecute = false;
info.CreateNoWindow = true;
Process p1 = new Process();
p1.StartInfo = info;
p1.Start();
string res = file.ReadToEnd();
file.Close();
// where encoding should be Encoding.UTF8;
MessageBox.Show(p1.StandardInput.Encoding.EncodingName);
p1.StandardInput.WriteLine(res);
p1.Close();
【问题讨论】:
标签: c# .net encoding utf-8 process