Archive: Best way to log errors


Best way to log errors
I have a code section which calls ExecWait and executes a batch file which runs a couple of postgresql commands to create and populate a database. I can turn off echo and pause the DOS cmd to view any errors that may occur but what I really need is a way to log the actual errors that are displayed in the DOS box. Here is my current code block. I have error handling on the ExecWait but it just tells me if the ExecWait failed overall, it doesn't have the granularity I need in case a non-tech customer runs into a problem. I need a log file of actual postgresql errors. Any help is greatly appreciated.

thanks
Nick

here is the current code block:


FileOpen $1 "createopenfiredb.bat" "w"
FileWrite $1 "@ECHO OFF$\r$\n"
FileWrite $1 "set PGPASSWORD=$password$\r$\n"
FileWrite $1 '"$PROGRAMFILES\PostgreSQL\8.4\bin\createdb.exe" -U postgres -h localhost --encoding=UNICODE openfire 2> "createopenfiredb_error.txt"$\r$\n'
FileWrite $1 '"$PROGRAMFILES\PostgreSQL\8.4\bin\psql.exe" -U postgres -h localhost -d openfire -f "openfire_postgresql.sql"$\r$\n'
FileWrite $1 '"$PROGRAMFILES\PostgreSQL\8.4\bin\psql.exe" -U postgres -h localhost -d openfire -f "openfire_update2.sql"$\r$\n'
#FileWrite $1 "PAUSE$\r$\n"
FileWrite $1 "exit %ERRORLEVEL%$\r$\n"
FileClose $1

DetailPrint "Creating openfire database."
ExecWait "createopenfiredb.bat" ; don't forget the .bat extension...
IfErrors +1 +3
Push "Creation of openfire database failed, please contact face2name with this error."
Call ErrorHandler
DetailPrint "Openfire database created."

You can use the ExecDos plugin, which has the ability to push the output to the stack (/TOSTACK option) (See plugin wiki for details / example: http://nsis.sourceforge.net/ExecDos_plug-in)

Why do you create a batch file?
You can set the password in the %APPDATA% directory (http://www.postgresql.org/docs/8.4/s...pq-pgpass.html) (which is safer as well), and run the 3 commands individualy with ExecDos calls, which gives you better track of what's happening as well.


I had found a project that used a batch file and was using that as an example. I am looking into the ExecDos method.

http://postgis.refractions.net/download/windows/

thanks
Nick


You might also check out nsExec. I don't have it in front of me, but there is an exectostack function which i use a lot when I'm calling SQLCMD,exe which is the same thing you're doing more or less.
You get the added benefit of nsExec automatically hiding the cmdshell window for you