我正在創建行程以在 C# 中運行 pg_dump.exe
var processStartInfo = new ProcessStartInfo
{
Arguments = @"-U postgres -W -f D:\postgres\test123_dump.sql postgres",
CreateNoWindow = true,
FileName = @"C:\PostgreSQL\bin\pg_dump.exe",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardInput = true
};
Process process = new Process() { StartInfo = processStartInfo, EnableRaisingEvents = true };
process.Start();
using( StreamWriter sw = process.StandardInput)
{
sw.WriteLine("123"); // test password
};
它將運行 pg_dump.exe,它會提示輸入密碼,但 StreamWriter 似乎由于某種原因無法作業。
uj5u.com熱心網友回復:
您可以使用此字串將您的身份驗證資訊直接放在引數串列中
var processStartInfo = new ProcessStartInfo
{
Arguments = @"--dbname=postgresql://user_name:pass_word@Localhost:5432/bd_name_to_save -F c -b -f output_bd_name",
CreateNoWindow = true,
FileName = @"C:\PostgreSQL\bin\pg_dump.exe",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardInput = true
};
Process process = new Process() { StartInfo = processStartInfo, EnableRaisingEvents = true };
process.Start();
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490589.html
標籤:C# PostgreSQL pg转储
上一篇:結構與類中欄位的聯鎖更新
