pg_dump 输出文件名中包含 UTF-8 字符时失败

pg_dump Fails When UTF-8 Characters In Output File Name

我正在尝试使用 pg_dump 创建数据库备份。数据库名称包含非ASCII字符,例如本物ではナイドータベース名。

我正在拨打以下电话:

pg_dump.exe --file="C:\Users\AUser\AppData\Local\Temp\本物ではないデータベース名_20150309185239.pgbak" pg_backupc4c978f4aebc4153adcabab6e097c347

但是失败并出现以下错误:

pg_dump: [archiver] could not open output file "C:\Users\AUser\AppData\Local\Temp\????????????_20150309185239.pgbak": Invalid argument

我不明白的是其他命令使用非 ASCII 字符。例如 mdkdir 本物ではないデータベース名 工作正常。

这是 pg_dump 中的错误还是我做错了什么?

更新

根据评论中的@Mike Sherrill 'Cat Recall',我测试了重定向,它在 Powershell 和标准命令行中都有效。

但是,我随后尝试使用 C# 自动执行此操作,当我尝试使用 C# 运行 上面的命令时 Process 它失败了:

        ProcessStartInfo psi = new ProcessStartInfo(command, args);
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = psi.RedirectStandardError = true;
        using (Process process = new Process())
        {
            process.StartInfo = psi;
            string s = "";
            process.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e)
            {
                s += e.Data;
            };
            string s1 = "";
            process.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e)
            {
                s1 += e.Data;
            };
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            TimeSpan maxTime = TimeSpan.FromMinutes(10);
            if (!process.WaitForExit((int)maxTime.TotalMilliseconds))
            {
                throw new Exception("Command " + command + " " + args + " Timed out after " + maxTime.TotalSeconds);
            }
            if (process.ExitCode != 0)
            {
                throw new Exception("Command " + command + " " + args + " failed with " + s + " " + s1);
            }
        }

同样,我可以制作一个 C# Process 并用日文字母调用 mkdir,一切正常。

根据@MikeSherrill'CatRecall':

"The file option --file is parsed and processed by pg_dump code, which might not be written to cope with UTF-16. (Source code) Redirection is done by the shell. If you want this to work, you'll need to either rewrite part of pg_dump(), or use command-line redirection."