Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# pg_转储进程中未写入任何文件_C#_Process_Postgresql 9.3 - Fatal编程技术网

C# pg_转储进程中未写入任何文件

C# pg_转储进程中未写入任何文件,c#,process,postgresql-9.3,C#,Process,Postgresql 9.3,我正在写一些c代码来备份我的Posgresql数据库 public static bool MakeBackup(string schema, string userName, string password, string backupFolder) { var database = "Import"; var timestamp = DateTime.Now.ToString("yyyyMMdd-HH-mm-ss"); var file = String.Format

我正在写一些c代码来备份我的Posgresql数据库

public static bool MakeBackup(string schema, string userName, string password, string backupFolder)
{
    var database = "Import";
    var timestamp = DateTime.Now.ToString("yyyyMMdd-HH-mm-ss");
    var file = String.Format("{0}_{1}.sql", schema, timestamp);
    var fullPath = String.Format(@"{0}\{1}", backupFolder, file);

    var executablePath = @"C:\Program Files\PostgreSQL\9.3\bin\pg_dump.exe";

    var arguments = String.Format(@" -h localhost -d{0} -n{1} -U{2} -w{3} > {4}",database, schema, userName, password, fullPath );

    Boolean result = false;
    try
    {
        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
        info.FileName = executablePath;
        info.Arguments = arguments;
        info.CreateNoWindow = true;
        info.UseShellExecute = false;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = info;
        proc.Start();
        proc.WaitForExit();
        result = true;

   }
   catch (Exception ex)
   {
        //Console.writeline(ex.Message);
   }
   return result;
}
一开始我遇到了一个拒绝访问的错误。我通过确保我的应用程序具有对输出文件夹的写入权限,并将
info.Arguments
设置为完整的pg_dump.exe路径来修复此问题

我尝试在调试中暂停,然后复制参数并在命令提示符下执行这些参数,效果很好

因此,我没有收到任何错误,但我的文件夹仍然是空的


有什么建议吗?

您正在尝试将pg_dump with>的输出转发到一个文件。这将不起作用,因为没有shell处理输出转发。相反,您应该使用pg_dump的选项
-f output_file
将输出保存到所需的文件中

此时,
>文件
将作为命令行参数发送到pg_dump,它可能显示错误,也可能不显示错误