C# 如何更改编码?
我需要转换或设置编码windows-1251C# 如何更改编码?,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 =
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
上进行设置。我想(我现在不是在编译器面前测试)。