Using Delphi
how can you find out of the psql script has returned
password authentication has failed for user "myadmin"
when running the following script(psqlRun.bat)
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h localhost -p 5433 -d TestDB -U myadmin -f someSQLscript.sql
The above script was ran using shellexecute
ReturnedValue:= ShellExecute(Handle,'open',PChar('C:\psqlRun.bat'), nil, nil, SW_SHOWNORMAL);
The returned value was over 32 (so it ran successfully)
but for me the password authentication failed..
is there any way to find through delphi is the script failed if the password failed?
Since the pgpass.conf may not have been created so i cant check the file for user password.
The user may not know the password or may have entered wrong password.
so programmatically how to check if the authentication failed?
Note : Postgresql 9.0
No, it does not mean it. http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153.aspx
It only means it had STARTED successfully. If the complete run was successful or not, MSDN hints there is no way to know using ShellExecute/ShellExecuteEx.
You should use CreateProcess to get running task handle, then WaitFor to get result or intercept it’s output to look for particular lines.
You can try Jedi Code Library, where JclSysUtils unit has Execute function and TJclCommandLineTool class to incapsulate this.
Example of use is JCL installer, which calls a number of command-line utils, like DCC32.EXE, capturing and saving their output to log and checking the return codes.
PS. And you’d better not using bat file for it. Make command line and run it directly. As of now you make it a tree.
Even if pgSQL.exe returns something, it does not return to your program but to CMD.exe
After that CMD.exe exposes that code into its internal variable %ERRORLEVEL%
And now you have to learn if it can pass that variable outside for your program.
Why that ? Every next indirection level make your program more isolated and fragile. Just call PG EXE directly without scripts. Otherwise you should program for CMD.EXE also – do you really need it ?