C# 如何更改编码?

C# 如何更改编码?,c#,encoding,C#,Encoding,我需要转换或设置编码windows-1251 Process p = new Process(); StreamWriter sw; StreamReader sr; StreamReader err; ProcessStartInfo psI = new ProcessStartInfo("cmd"); psI.UseShellExecute = false; psI.RedirectStandardInput = true; psI.RedirectStandardOutput =

我需要转换或设置编码windows-1251

Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;



ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;

psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;


p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
err = p.StandardError;



sw.AutoFlush = true;
if (tbComm.Text != "")
    sw.WriteLine(tbComm.Text);
else
    //execute default command
    sw.WriteLine("dir \\");


sw.Close();

textBox1.Text = sr.ReadToEnd();// this not support russian word. I need convert or set encoding windows-1251
textBox1.Text += err.ReadToEnd();

在将
StreamReader
指向
StreamReader
之前,您应该能够在
ProcessStartInfo
上为
standard output
设置一个目标

在将
StreamReader
指向
流阅读器之前,您应该能够在
进程StartInfo
上为
标准输出

psI.StandardOutpuneCoding=Encoding.GetEncoding(1251);-帮不了我。可能会改变StreamReader编码吗?@simply denis:我可能错了,但我认为
StreamReader
编码只能在构建时设置。之后它是只读的。由于它是在
进程
中构造的,因此需要在
进程
进程StartInfo
上进行设置。我想(我现在不在编译器前面测试)帮不了我。可能会改变StreamReader编码吗?@simply denis:我可能错了,但我认为
StreamReader
编码只能在构建时设置。之后它是只读的。由于它是在
进程
中构造的,因此需要在
进程
进程StartInfo
上进行设置。我想(我现在不是在编译器面前测试)。