Jump to content
Sign in to follow this  
Aktonius

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

Recommended Posts

Aktonius

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

Share this post


Link to post
Share on other sites
careca

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

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
Aktonius

Closing/opening file handle every second somehow worries me about memory/processor usage or general overkill that might lead to unexpected things but maybe i am just paranoid, thanks for suggestion as thats something i can try.

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
kylomas

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

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  

×