Jump to content

FileWriteLine question (noob here)


Recommended Posts

Hello,

as many other i want a log file. I started with opening a notepad and sending text to it, which worked perfectly, but wasnt what i wanted.

So i found FileWriteLine.

But this one confused me.......When entered in the program it wouldnt do its job. There were simply hardly any entries. So i decided to make next script as test.

#include <Date.au3>

WriteToLog2("Started Sequence")

Func WriteToLog2($Message)

$logfile2=FileOpen("logfile2.log", 1)

$tCur = _Date_Time_GetLocalTime()

If $logfile2 = 0 Then

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

Exit

EndIf

FileWriteLine( $logfile2, _Date_Time_SystemTimeToDateTimeStr($tCur) & " " & $message)

FileClose("logfile2.log")

EndFunc

WriteToLog2("Hallo World")

WriteToLog2("En dit is de tweede regel")

;sleep (400000)

And this works perfect. I embedded this one in the big program....no go again ;)

So to try to find out what happens i added the sleep(40000).

Result: It seems that if the programm doesnt quit right after the write statement it wont write at all...

With sleep>>no writelines in my log.....without sleep>>>>they are there..

What do I wrong?

regards,

William

Edited by WilliamWhite
Link to comment
Share on other sites

I use it like this

$file=FileOpen("log.txt",1)
if($file<>-1)then
  FileWriteLine($file,$logtext)
  FileClose($file)
endif

And never had any problems. I also have an else in there wich sleeps for 10 miliseconds and tries to re-open the file depending on other options..

---Edit1

You have if $fileHandler=0

In the autoit help file it says that on failure it returns -1, not zero

Edited by madScientist
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...