Jump to content

Constantly reading a log file from 3rd party application...


 Share

Recommended Posts

It baffles me why is everything ok but sometimes all of sudden the file handle becomes unreadable even there is a new data cosntantly added to it, the only solution becomes to close Auto-it process that opened the handle and re-open it again after relaunch.

So the procedure is simple

$xml = FileOpen("c:\path_to_file.xml")

while 1
$data = FileRead($xml)
consolewrite("inspecting data >"&$data&@lf)
wend

But then all of sudden sometimes the handle just becomes undreadable and FileRead() returns blank even it shouldnt(new data is added constantly...) :(

Any other method i could try to avoid this?

Edited by Aktonius
Link to comment
Share on other sites

Hi, because the file is being used by another aplication, maybe you need to close, and reopen before you read again.

Not sure, just guessing.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Aktonius,

I would read it like this

while 1
    $xml = FileOpen("c:\path_to_file.xml")
    if $xml = -1 then msgbox($mb_systemmodal,'File Open Error',$xml)
    $data = FileRead($xml)
    consolewrite("inspecting data > " & $data & @lf)
    fileclose($xml)
    $xml = 0
    sleep(1000)
wend

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Aktonius,

I understand your concern. I think that setting the file handle to "0" releases the resources. However, you could try to serialize the access using "_winapi_fileinuse" in Yashied's WINAPIex UDF (sorry, don't have the link).

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Aktonius,

Yashied's UDF is

It might be used like this

#include <winapiex.au3>
$xml = @scriptfullpath
while 1
    if _winapi_fileinuse($xml) = 1 then
  $data = FileRead($xml)
  consolewrite("inspecting data > " & $data & @lf)
 Else
  ConsoleWrite($xml & ' in use' & @LF)
 endif
    sleep(1000)
wend

* - note

The fileread using the filename does an open/close. The more I think about it, the more sense it makes to do an explicit open/close and set the file handle to '0' to free resources. I don't know if the above implicit open/close does this.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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