什么是 cmd.exe 编码的正确 c# 输入流 [英] whats the right c# input stream for cmd.exe encoding

查看:53
本文介绍了什么是 cmd.exe 编码的正确 c# 输入流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的 c# 应用程序启动一个 cmd.exe 并重定向它的输入流.这适用于像abc"这样的普通字符但是当我尝试在控制台窗口中重定向像äöüßáàâ"这样的字符时会出现õ÷³óô".

I am starting a cmd.exe from my c# application and redirect its inputstream.This works fine for normal chars like "abc" But when i try to redirect chars like "äöüßáàâ" in the consolewindow appears "õ÷³óô".

Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/K";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;

myProcess.StartInfo.WorkingDirectory = @"c:\";
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.WriteLine("äöüßáàâ");

myStreamWriter.Encoding 说它的编码是代码页 1252 我试图将我的字符串转换成它,但它没有改变结果.如何转换显示正确的字符串?

myStreamWriter.Encoding says its encoding is codepage 1252 i tryed to convert my string into it but it didnt change the result. How to convert my string that it is shown correct?

推荐答案

我拿了代码,跑了一样.. 没有重定向输出的时候,看到的和OP一样.不过

I took the code and ran the same.. When I didnt redirect the output, I saw the same as the OP. However

Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/K";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
//myProcess.StartInfo.StandardOutputEncoding = Encoding.UTF32;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.WorkingDirectory = @"c:\";
myProcess.Start();

StreamWriter myStreamWriter = myProcess.StandardInput;
StreamReader myStreamReader = myProcess.StandardOutput;
myStreamWriter.WriteLine("äöüßáàâ");
richTextBox1.Text = myStreamReader.ReadToEnd();

这在文本框中按预期产生了 c:\>äöüßáàâ.. 即使它似乎没有在显示的控制台窗口中正确显示.

This produced c:\>äöüßáàâ as expected in the text box.. even though it didnt seem to show it as right in the console window that showed.

这篇关于什么是 cmd.exe 编码的正确 c# 输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆