fRequEnCy Posted January 28, 2010 Posted January 28, 2010 Hello all. Forgive my ignorance. I was working on a script and all was working fine and then decided to update to current version to apply logging of new OS (Win 7). Well to my surprise my script no longer logs. So I did a basic script for testing and sure enough I can't get it to work. Here is test script: #include <File.au3> if Not FileExists(@ScriptDir & "\log.txt") Then _FileCreate(@ScriptDir & "\log.txt") EndIf FileOpen(@ScriptDir & "\log.txt", 2) _FileWriteLog(@ScriptDir & "\log.txt", "testing 1") _FileWriteLog(@ScriptDir & "\log.txt", "testing 2") According to help file: Return Value Success: Returns a file "handle" for use with subsequent file functions. Failure: Returns -1 if error occurs. So I tested with a message box and gave FileOpen a variable and it returned a 1. So maybe this is where I'm having issues? I also did a full uninstall and reinstall to make sure I didn't do something wrong in the upgrade. Any help is appreciated.
water Posted January 28, 2010 Posted January 28, 2010 I think you mix up two things. Fileopen returns a handle. But if you never use the handle in your script then this is not needed. _FileWriteLog doesn't use a handle. So it opens the file, writes the text and closes the file. Thus having said I would change your script to: #include <File.au3> _FileWriteLog(@ScriptDir & "\log.txt", "testing 1") _FileWriteLog(@ScriptDir & "\log.txt", "testing 2") My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
fRequEnCy Posted January 28, 2010 Author Posted January 28, 2010 I think you mix up two things. Fileopen returns a handle. But if you never use the handle in your script then this is not needed. _FileWriteLog doesn't use a handle. So it opens the file, writes the text and closes the file. Thus having said I would change your script to: #include <File.au3> _FileWriteLog(@ScriptDir & "\log.txt", "testing 1") _FileWriteLog(@ScriptDir & "\log.txt", "testing 2") That worked great! Thanks for the tip. Creates the file and all so no need for all that extra junk. Another question that I now have is how do I clear the contents in the beginning so that it creates a new log everytime? That's why I thought I had to use FileOpen with mode 2 to erase the previous contents.
water Posted January 28, 2010 Posted January 28, 2010 Just delete the file with FileDelete. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
fRequEnCy Posted January 28, 2010 Author Posted January 28, 2010 Just delete the file with FileDelete.LOL. Well that makes sense and is an easy solution. Many thanks for your quick responses and help. Now I can move forward with my script. Just weird that it worked before the update. But no matter since was going about it all wrong anyways.
water Posted January 28, 2010 Posted January 28, 2010 There have been some changes in the latest versions of AutoIt regarding file handling. All changes (including script breaking changes) are documented here. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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