I created a .bat to perform the restoration of a database in PostgreSQL and it worked perfectly using the following command:
set PGPASSWORD=postgres123
C:\Progra~1\PostgreSQL.4\bin\pg_restore.exe -i -h localhost -p 5432
-U postgres -c -d dbrestore -v D:\bkp.backup
Now I want to run a bat to do this in C #. I'm running this function:
static void Restore()
{
Environment.SetEnvironmentVariable("PGPASSWORD", clsConfigBanco.PASSWORD);
const string exe = @"C:\Progra~1\PostgreSQL.4\bin\pg_restore.exe";
const string arg = "-i - h localhost - p 5432 - U postgres - c - d dbrestore - v D:\bkp.backup";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = exe;
startInfo.Arguments = arg;
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
The problem is that this function does not execute the bat. it just blinks and disappears. how can I do a function to execute this bat? and I have to generate it at runtime because not always the variables will be the same