如何改变编码?

时间:2011-01-17 18:29:12

标签: 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 = 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();

1 个答案:

答案 0 :(得分:0)

StandardOutput指向ProcessStartInfo之前,您应StreamReader {{1}} {{1}}。