Setup/Running PostgreSQL From C#
.net, c#, localization, postgresql, process
Solution
(we are doing something similar) you star the `Postgres` service by using this batch file
"C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe" -D "C:\Program Files\PostgreSQL\9.0\data" start
and for [Stopping] the service
"C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe" -D "C:\Program Files\PostgreSQL\9.0\data" stop
where `C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe` is the location of your installation of `PostgreSQl` which u can get from
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-9.0
Now on running the Batch file to check if the service is indeed running you can use this code from Process running check for `postgres.exe` if its running or not.
Also 1. checking-if-windows-application-is-running 2. how-can-i-know-if-a-process-is-running
public bool IsProcessOpen(string name)
{
//here we're going to get a list of all running processes on
//the computer
foreach (Process clsProcess in Process.GetProcesses()) {
//now we're going to see if any of the running processes
//match the currently running processes. Be sure to not
//add the .exe to the name you provide, i.e: NOTEPAD,
//not NOTEPAD.EXE or false is always returned even if
//notepad is running.
//Remember, if you have the process running more than once,
//say IE open 4 times the loop thr way it is now will close all 4,
//if you want it to just close the first one it finds
//then add a return; after the Kill
if (clsProcess.ProcessName.Contains(name))
{
//if the process is found to be running then we
//return a true
return true;
}
}
//otherwise we return a false
return false;
}
Problem
My requirements are as follows: - Once the application starts the PostgreSQL service will be started by the application - Once the application closes the PostgreSQL service will be closed by the application - ... so i will be taking care of the PostgreSQL setup and running the scripts and starting the service etc How i am doing this at present is: - when i start PostgreSQL in a new process i am redirecting the `RedirectStandardError` and `RedirectStandardOutput`, it is a silent start, user cannot see the command window etc The problem is, - When I coded this I looked for message strings and only supported English. In other words, I used to look for the string `success` in `RedirectStandardOutput` but now we are supporting multiple languages so the comparison fails. Is there any way i can find out whether PostgreSQL set up was successfully started and PostgreSQL service is running or not? I am starting PostgreSQL by calling pg_ctl.exe in separate process.