Sign in to follow this  
Followers 0
BSherry

FileRead EOF on active file

4 posts in this topic

While trying to read the log file of another running program, FileReadLine gets confused by terminal control characters in the file (NULL's, Escapes, etc.), so I wrote one, that uses FileRead($fh, 1), to strip control codes. Terminating a line with a carriage return is easy, but when the line doesn't end yet, I am having problems figuring out how to return the partial line, because in this case, FileRead doesn't seem to return the EOF indication.

Here is the code as it exists:

#cs*********************************************************************

* File Get A Line

* Inputs filehandle.

* Modifies Global $LineToGet

*

* Why? because FileReadLine gets confused with control characters

#ce*********************************************************************

Func FileGetALine($inputfile)

Dim $mychar = ""

Dim $retstring

while 1

$mychar = Asc(FileRead($inputfile, 1))

If @error = 0 Then

; if it is a space or bigger

If $mychar >= 0x20 Then

$LineToGet &= Chr($mychar)

; if it is a carriage return or line feed

ElseIf $mychar = 0x0d Then

$retstring = $LineToGet

$LineToGet = ""

ExitLoop

ElseIf $mychar = 0x0a Then

$LineToGet = ""

; replace tabs with a space

ElseIf $mychar = 0x09 Then

$LineToGet &= " "

EndIf

Else

; keep going till EOF

MsgBox(0, "error", @error)

$retstring = $LineToGet

ExitLoop

Endif

WEnd

Return $retstring

EndFunc

Any Ideas?

Share this post


Link to post
Share on other sites



After FileRead if @error = -1 then end-of-file is reached.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

After FileRead if @error = -1 then end-of-file is reached.

That is what I was hoping, and what should have happened, but it doesn't always seem to. That is what the "; keep going till EOF" is about. FileReadLine will return a partial line, but it may have control characters in it, which need to be stripped.

What I see, is that the file stops growing, the text I am looking for is in it, but AutoIt hasn't returned the line.

What I have done for now, is to make sure the error's I was looking for don't happen, then I can just use FileRead.

Bruce

Share this post


Link to post
Share on other sites

Have you tried opening the file in binary mode. Nulls are interpreted by AutoIt as a string termination that would explain why you don't get all the expected data. You can always convert the fileread binary variant to a string variant if required after filtering out nulls.

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