Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
String command = "";
//備份位置
String outputPath = @"C:\";
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
command = @"cd C:\Bitnami\postgresql\bin";
p.StandardInput.WriteLine(command);
command = @"pg_dump -U " + "DB帳號" + " -d " + "DB密碼 + " -f " + outputPath + "檔名.sql";
//執行備份
p.StandardInput.WriteLine(command);