WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Selva1981 on October 15, 2013, 01:45:14 PM

Title: How to implement log mechanism in Winbatch Studio
Post by: Selva1981 on October 15, 2013, 01:45:14 PM
Hi.

We are using Winbatch script to do varios process, like calling DTS packages, ZIP and UNZIP the file etc....
We would like to implement the log mechanism each step of the process.
Please assist us on this.

Thanks
K. Selvaraj.

Title: Re: How to implement log mechanism in Winbatch Studio
Post by: Deana on October 15, 2013, 01:56:29 PM
Depends on what type of logging you want to do.  To simply report events that occur during normal operation of a script you can use FileOpen, FileWrite and FileClose to create a simple log file.

If you are actually interested in logging errors then you might want to implement an error handling mechanism. see: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+Trap~Errors.txt
Title: Re: How to implement log mechanism in Winbatch Studio
Post by: Selva1981 on October 15, 2013, 02:09:48 PM
Hi Deana,
Thanks for your quick reply.

We are new to WIL script. So we are looking to write all type of errors. Means that whenever the error occured during the process, we need to write those error in seperate text(txt) file in some location and see it what happened.
Please provide your advice on this and share some forum if you have same like this.

Thanks
K. Selvaraj.
Title: Re: How to implement log mechanism in Winbatch Studio
Post by: Deana on October 15, 2013, 02:45:13 PM
The link I posted above should be helpful. Here it is again in case you missed it:  http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+Trap~Errors.txt

Here is simple code sample that should help get you started:


Code (winbatch) Select
;***************************************************************************
;**
;**   Error Logging Sample
;**
;***************************************************************************
errlog = DirScript():'ErrorLog.txt'
errloghandle = FileOpen( errlog, 'WRITE')

IntControl(73,1,0,0,0)

badline = Message("aaaa",bbb) ;Sample error

; Clean up
FileClose( errloghandle )
EXIT

:WBERRORHANDLER
time = TimeYmdhms()
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errstr = StrCat(`Time:`,time, `,Number:`,lasterr,`,String:`,textstring,`,Line:`,linenumber,`,Code:`,handlerline)
FileWrite( errloghandle, errstr )
Exit