Jump to content
Sign in to follow this  
jfornango

FileWriteLine stops working in mid-run

Recommended Posts

jfornango

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.

; 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?

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

 

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

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×