swapnil Posted October 10, 2010 Share Posted October 10, 2010 I have a file which is updated in interval of nearly in a second by an app.If I read it using notepad it shows the updated value each time I open it,but If I try to read it in autoit (using following script) it shows the older contents again and again. Can any one help me here ??? Here's my script #include<array.au3> #include <file.au3> Dim $aRecords If Not _FileReadToArray("test1.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $v=_ArrayToString($aRecords) $d = StringSplit($v,"~") Msgbox(0,'Record:' ,$d[1]) Msgbox(0,'x' ,Int($d[2])) Msgbox(0,'y' ,Int($d[3])) MsgBox(0,'z' ,Int($d[4])) I have attached sample of file which I am reading.test1.txt Link to comment Share on other sites More sharing options...
taietel Posted October 10, 2010 Share Posted October 10, 2010 (edited) See if this helps you: #include<array.au3> #include <file.au3> Dim $aRecords HotKeySet("{ESC}","_Exit") AdlibRegister("ReadTheFile",1000) While 1 Sleep(10) WEnd Func ReadTheFile() If Not _FileReadToArray("test1.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $v=_ArrayToString($aRecords) $d = StringSplit($v,"~") ConsoleWrite('Record:' & $d[1]&@CRLF&'x ' &Int($d[2])&@CRLF&'y ' &Int($d[3])&@CRLF&'z ' &Int($d[4])&@CRLF&@CRLF) EndFunc Func _Exit() AdlibUnRegister() Exit EndFunc M.I. [EDIT] Jos is right (see the next post) Edited October 10, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Developers Jos Posted October 10, 2010 Developers Share Posted October 10, 2010 @taietel, Couple of remarks/questions: 1. Never use a close loop without a brief Sleep(10)! 2. Why are you reading the file into an array and then merge the array into a string? Just read the whole file directly into the string! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
taietel Posted October 10, 2010 Share Posted October 10, 2010 Jos, thank you for the remarks! 1. My mistake 2. I just replaced the msgboxes with the console output to avoid the appearance of 4 msgboxes every second (just for showing the output) Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now