Sign in to follow this  
Followers 0
AuxMax

writing to a log file...

7 posts in this topic

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....

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

look up

_FileWriteLog()

in help

8)

BTW

Welcome to the forums

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

PS you donot need File.au3 for Filewriteline()

if using _Filewritelog you don't need Date.log

Share this post


Link to post
Share on other sites

Thanks for the responses. wOuter was on the money with the quotes, however, I'll look at the _Filewritelog as well...thanks Valuator.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.


[center]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.[/center]

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  
Followers 0