Jump to content

writing to a log file...


AuxMax
 Share

Recommended Posts

Newbie here....first post. Have figured out most of my issues previously, but this one doesn't jive.

I'm writing a script to upgrade an application. As part of the upgrade process, I have included error log creations in case the upgrade fails. Using _FileCreate, the log file name is the computer name (using @Computer) concatinated with the LOG extension. This part works.... However, when I try to FileWriteLine or FileWrite the canned error message, I get an empty file.

Now, if I modify the code to simply create a static file name, like PC.log, it writes as expected.

Huh? :P

Here's the code:

#include <file.au3>

#include <date.au3>

Dim $file

$file = FileOpen ( '"c:\temp\" & @ComputerName & ".log"' , 2 )

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWriteLine( $file , "It's broke.")

FileWriteLine( $file , "Date and Time:" & _Now())

FileClose($file)

I have full rights to the temp directory. I've also tried other folders to no avail.

Insight would be extremely helpful....

Link to comment
Share on other sites

wrong quotes, this should work:

$file = FileOpen ( "c:\temp\" & @ComputerName & ".log" , 2 )

OR

$file = FileOpen (@tempdir & '\' & @ComputerName & '.log', 2)

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

it should be noted that scite editor doesn't prompt you to include file.au3 if you use file operations. the exe compiles, runs, but the file operations don't happen. took me a while to figure out I hadn't included it.

Hmmm, I know that I test everything I do before I compile it in SciTe. And an error is thrown if I'm calling for a function that isn't either 'A' in the script or 'B' in one of the #include <> files.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...