为什么command不't执行如果包含俄语字母

本文关键字:包含俄 如果 执行 command 为什么 | 更新日期: 2023-09-27 18:09:32

我试图断开/连接我的调制解调器适配器,命名为"конект",但它不起作用,因为适配器的名称包含俄语字母。如何强迫它工作?请帮助。

Connect("конект", ", ", true);

    public static void Connect(string adapter, string login, string pass, bool discon)
    {
        string cmd = "";
        if (discon)
        {
            cmd = "rasdial " + '"' + adapter + '"' + @" /disconnect";
        }
        else
        {
            cmd = "rasdial " + '"' + adapter + '"' + " " + login + " " + pass;
        }
        Cmd(cmd);
    }
    public static void Cmd(string URL)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe");
        Process p = new Process();
        startInfo.RedirectStandardInput = true;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardError = true;
        startInfo.CreateNoWindow = true;
        p = Process.Start(startInfo);
        p.StandardInput.WriteLine(URL);
        p.StandardInput.WriteLine(@"EXIT");
        p.WaitForExit();
        p.Close();
    }

[我知道只需要用英文字母和代码重命名适配器就可以了,但我想知道如何强制它与俄语字母一起工作]

为什么command不't执行如果包含俄语字母

    p.StandardInput.WriteLine(URL);

ProcessStartInfo缺少一个StandardInputEncoding属性。这使得包含西里尔字符的"URL"字符串很可能在没有西里尔代码页作为默认系统代码页的机器上运行时被打乱。

您确实希望避免在这里使用输入重定向,它只是没有必要。对cmd.exe使用/c命令选项,这样就可以直接传递命令行:

startInfo.Arguments = "/c " + URL;
p = Process.Start(startInfo);

不需要使用cmd.exe,直接运行rasdial.exe即可

相关文章: