相关疑难解决方法(0)

如何在C#中获取CMD /控制台编码

我需要指定正确的代码页来打包带有zip库的文件.我看,我需要指定控制台编码(在我的情况下为866).

 C:\Users\User>mode

 Status for device CON:
 ----------------------
     Lines:          300
     Columns:        130
     Keyboard rate:  31
     Keyboard delay: 1
     Code page:      866 <- I need to get this value in C# code
Run Code Online (Sandbox Code Playgroud)

Console.OutputEncoding返回1251,这不是我需要的.

谢谢,

亚历克斯

更新1:显然,在cmd.exe中执行"mode"并解析输出应该有效但看起来太粗鲁了.我正在寻找.NET解决方案.

更新2:应用程序是Windows窗体应用程序,而不是控制台应用程序.

c# console cmd

10
推荐指数
1
解决办法
4210
查看次数

编码UTF8 C#进程

我有一个处理vbscript并生成输出的应用程序.

private static string processVB(string command, string arguments)
{
    Process Proc = new Process();
    Proc.StartInfo.UseShellExecute = false;
    Proc.StartInfo.RedirectStandardOutput = true;
    Proc.StartInfo.RedirectStandardError = true;
    Proc.StartInfo.RedirectStandardInput = true;
    Proc.StartInfo.StandardOutputEncoding = Encoding.UTF8;
    Proc.StartInfo.StandardErrorEncoding = Encoding.UTF8;
    Proc.StartInfo.FileName = command;
    Proc.StartInfo.Arguments = arguments;
    Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console      window from popping up
    Proc.Start();
    string output = Proc.StandardOutput.ReadToEnd();
    string error = Proc.StandardError.ReadToEnd();

    if (String.IsNullOrEmpty(output) && !String.IsNullOrEmpty(error))
    {
        output = error;
    }
    //Console.Write(ping_output);

    Proc.WaitForExit();
    Proc.Close();

    return output;
}
Run Code Online (Sandbox Code Playgroud)

我想我已经设置了与编码属性相关的所有内容.processVB方法将获取命令作为VBscript文件及其参数.

C#方法processVB正在处理现在生成输出的VBScript文件,如下所示.

"?"

但我应该得到原文

"äåéö€"

我已正确设置编码.但我无法做到正确.

我究竟做错了什么?

c# encoding process utf-8

6
推荐指数
1
解决办法
6069
查看次数

标签 统计

c# ×2

cmd ×1

console ×1

encoding ×1

process ×1

utf-8 ×1