jfornango Posted November 6, 2013 Share Posted November 6, 2013 So, I am working on a process, and am using FileWriteLine to write out data to a log file. For the most part, this is working exactly as expected. The problem comes at the end of the run. Right before I close the program, I write out one last status line and then issue a FileClose. When I look at the log file, everything is there, except the last line that I write out. Here's the basic set up. expandcollapse popup; do some prep work _prep() _setupGUI() While 1 $ctrl_msg = GUIGetMsg() Select Case $ctrl_msg = $GUI_EVENT_CLOSE ExitLoop Case $ctrl_msg = $btnExit ExitLoop Case $ctrl_msg = $btnBackup _dataBackup() _rptBackupSummary() _IECreate($strBackSum) FileWriteLine($strProcessLog, _NowTime() & " Run Completed normally") ExitLoop Case $ctrl_msg = $btnCancel _dataCancel() EndSelect WEnd Exit #cs ***************************************************************************** Backup #ce ***************************************************************************** Func _Backup() ; Create the backup folder in the location, and set up the backup log files DirCreate ($strDataLoc & "\" & @UserName & "\" & $strBackupFolder) $strTarget = $strDataLoc & "\" & @UserName & "\" & $strBackupFolder DirCreate ($strTarget & "\Logs") DirCreate ($strTarget & "\RegistryFiles") DirCreate ($strTarget & "\Outlook") $strProcessLog = $strTarget & "\Logs\Backup.log" FileOpen($strProcessLog, 9) FileWriteLine ($strProcessLog, "Backup Started: " & _Now()) FileWriteLine ($strProcessLog, "Machine Name: " & @ComputerName) FileWriteLine ($strProcessLog, "User: " & @UserName & @CRLF & @CRLF) ; ... do some stuff ... FileWriteLine($strProcessLog, _NowTime() & $strUpdate) ; ... do more stuff FileWriteLine($strProcessLog, _NowTime() & $strUpdate) ; ... etc, etc.... FileWriteLine($strProcessLog, _NowTime() & $strUpdate) End Func Ok, so you get the basic jist of what I'm doing. The only thing I can think of, is that the log file is being closed when I end the function, so the final FileWriteLine (in the Select) isn't going anywhere. Am I following this correctly, or have I missed something else completely? Link to comment Share on other sites More sharing options...
kylomas Posted November 7, 2013 Share Posted November 7, 2013 jfornango, The filewriteline in the select only happens when the $btnBackup control is actioned. If this is not the problem, post the entire script. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
water Posted November 7, 2013 Share Posted November 7, 2013 Your usage of FileOpen is wrong. FileOpen returns a handle which then should be used by all subsequent writes and FileClose: $hLog = FileOpen($strProcessLog, 9) FileWriteLine ($hLog, "Backup Started: " & _Now()) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted November 7, 2013 Share Posted November 7, 2013 Your usage of FileOpen is wrong. FileOpen returns a handle which then should be used by all subsequent writes and FileClose: That is all true but I don't think that is his problem. FileWriteLine opens and closes the file with each write when a file name is the 1ST parm as seen in this code... local $myFile = @scriptdir & '\test.txt' local $hfl = fileopen($myFile,9) filewriteline($myFile,'line 1') filewriteline($myFile,'line 2') filewriteline($myFile,'line 3') If the OP is expecting a filewriteline at code termination it is not being shown in the script he posted. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
water Posted November 7, 2013 Share Posted November 7, 2013 The FileOpen "bug" was the only quite obvious problem. Don't have the time to dig deeper intot he code. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now