开发者

C# WinForms Process Encoding problem

I am writing a windows forms application in C# I have a Process Object which runs a cmd command and returns it's output.

Process Pro = new Process();
Pro.StartInfo.FileName = "cmd.exe";
Pro.StartInfo.Arguments = "<Dos Command here>";
Pro.StartInfo.CreateNoWindow = true;
Pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Pro.StartInfo.RedirectStandardOutput = true;
Pro.StartInfo.UseShellExecute = false;
Pro.Start();

Which works fine! However if the output of the command is not ASCII(in my case Greek), the Output are random symbols. Surely an encoding problem. If i run the same code on a console application everything runs smoothly.

I tried reading the Base stream as UTF-8, but no luck!

System.IO.StreamReader Rdr = new开发者_JS百科 System.IO.StreamReader(Pro.StandardOutput.BaseStream, Encoding.UTF8);

Is there any way to read the output properly in a winform application? Thnx!


The real solution is base on this: unicode-characters-in-windows-command-line-how check here: Wiki code page for the code page you need.

you can also do an ugly hack, writing the command to a batch file (f.e foo.bat) then running it as foo.bat > log.txt then you can read the output from log.txt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜