在自定义操作中读取 Process 的输出不会 return 符号选择语言 Wix

Read output from Process in custiom action dont return symbols selected language Wix

我在自定义操作 Wix 和控制台应用程序中使用相同的代码。在自定义操作中,它不会 return 修饰自定义操作中的符号“ł”和“±”。用其他符号或空格替换它们。在控制台应用程序中运行良好。

“消息”变量中已经没有波兰语字母。

    private static void RunTest(Session session)
    {
        try
        {
            Process p = CreateProcess();
            p.StartInfo.FileName = "....exe"; ;
            p.StartInfo.Arguments = "-t";

            string message = "";
            int errorCount = 0;
            p.OutputDataReceived += (sender, args) =>
            {
                if (args.Data == null)
                    return;
                message += args.Data;
                message += "\n";
            };
            p.ErrorDataReceived += (sender, args) =>
            {
                if (args.Data == null)
                    return;
                errorCount++;
                message += args.Data;
                message += "\n";
            };

            p.Start();
            p.BeginOutputReadLine();
            p.WaitForExit();
            SaveNewRtf(session, message);
        }
        catch (Exception)
        {
        }
    }

    private static Process CreateProcess()
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.CreateNoWindow = true;
        return p;
    }

编辑:

发生这种情况是因为来自 Process 的消息采用 Unicode。但不幸的是,我不知道如何修复它。我通过 Process 将程序 I 运行 中的消息编码更改为 utf-8,但消息仍以 Unicode 下载。

我通过

解决了
p.StartInfo.StandardOutputEncoding = OemEncoding.GetDefaultOemCodePageEncoding();

public static class OemEncoding
{

    private const Int32 MAX_DEFAULTCHAR = 2;

    private const Int32 MAX_LEADBYTES = 12;

    private const Int32 MAX_PATH = 260;

    private const UInt32 CP_OEMCP = 1;

    public static Encoding GetDefaultOemCodePageEncoding()

    {

        CPINFOEX cpInfoEx;

        if (GetCPInfoEx(CP_OEMCP, 0, out cpInfoEx) == 0)

            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,

                                                              "GetCPInfoEx() failed with error code {0}",

                                                              Marshal.GetLastWin32Error()));

        return Encoding.GetEncoding((int)cpInfoEx.CodePage);

    }

    [DllImport("Kernel32.dll", EntryPoint = "GetCPInfoExW", SetLastError = true)]

    private static extern Int32 GetCPInfoEx(UInt32 CodePage, UInt32 dwFlags, out CPINFOEX lpCPInfoEx);

    [StructLayout(LayoutKind.Sequential)]

    private unsafe struct CPINFOEX

    {

        internal UInt32 MaxCharSize;

        internal fixed Byte DefaultChar[MAX_DEFAULTCHAR];

        internal fixed Byte LeadByte[MAX_LEADBYTES];

        internal Char UnicodeDefaultChar;

        internal UInt32 CodePage;

        internal fixed Char CodePageName[MAX_PATH];

    }
}