foolet Posted June 29, 2010 Share Posted June 29, 2010 I keep trying and trying but I keep failing... I was hoping someone could help me with this I need to make a autoit script that basically let's you choose a log file then displays its contents in real time in a dos box. Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 29, 2010 Share Posted June 29, 2010 You mean reading a file displaying its content and then updating the content in a loop e.g. every 10 ms ? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 (edited) Try this:expandcollapse popup;Coded by UEZ Build 2010-06-30, thanks to KaFu for the hint ;-) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $iMemo, $new_line $width = 1024 $height = 600 $hGUI = GUICreate("Realtime Log Reader by UEZ 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST) $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY) GUICtrlSetLimit(-1, 0x7FFFFFFF) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then $file = $CmdLine[1] Else $file = @WindowsDir & "\WindowsUpdate.log" EndIf $hFile = FileOpen($file) $txt = FileRead($hFile) GUICtrlSetData($iMemo, $txt, 1) _GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff) $cl = _FileCountLines($file) $fs = FileGetSize($file) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While Sleep(1000) $fs_new = FileGetSize($file) If $fs < $fs_new Then $cl_new = _FileCountLines($file) For $i = $cl + 1 To $cl_new $new_line &= FileReadLine($hFile, $i) & @CRLF Next GUICtrlSetData($iMemo, $new_line, 1) ;~ _GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff) $cl = $cl_new $fs = $fs_new $new_line = "" EndIf Wend Func _Exit() FileClose($hFile) GUIDelete($hGUI) Exit EndFuncIt will read the WindowsUpdate.log and display it. If you run wuauclt /detectnow the log file will be updated and displayed in the GUI.I don't know whether it will work properly... If not please report!BR,UEZ Edited June 30, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 (edited) Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $iMemo, $new_line $width = 1024 $height = 800 $hGUI = GUICreate("Test", $width, $height, -1, -1, Default, $WS_EX_TOPMOST) $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY) GUICtrlSetLimit(-1, 0x7FFFFFFF) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") $file = @WindowsDir & "\WindowsUpdate.log" $hFile = FileOpen($file) $txt = FileRead($file) MemoWrite($txt) ControlSend($hGui, "", $iMemo, "{DOWN}") _GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff) $cl = _FileCountLines($file) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While 1 $cl_new = _FileCountLines($file) If $cl < $cl_new Then For $i = $cl + 1 To $cl_new $new_line &= FileReadLine($hFile, $i) & @CRLF Next MemoWrite($new_line) _GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff) $cl = $cl_new EndIf Sleep(500) Wend Func _Exit() FileClose($hFile) GUIDelete($hGUI) Exit EndFunc It will read the WindowsUpdate.log and display it. If you run wuauclt /detectnow the log file will be updated and displayed in the GUI. BR, UEZ I get "Auto it Error Line 4291 (File "CENSORED\test.exe"); Error: Unknown function name." Edited June 29, 2010 by foolet Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 What are you doing with the script? Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 Never mind I ran just the script and not the build and I get "Autoit Error Line 19 MemoWrite($txt) ^ERROR Error:Unknown function name." Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 (edited) Ups, forgot that function....See my post with the code!Sorry,UEZ Edited June 29, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 (edited) Thanks for your help. Edited June 29, 2010 by foolet Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 (edited) I just added it. ; Write a line to the memo control Func MemoWrite($sMessage) ;~ GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) GUICtrlSetData($iMemo, $sMessage, 1) EndFunc ;==>MemoWrite BR, UEZ Edited June 29, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 (edited) Never Mind fixed it Edited June 29, 2010 by foolet Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 Is there a way I can make new logs appear at the bottom? Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 Check my 3rd post. I updated the script. It should work now that the latest entries will be displayed at the bottom. BR, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 29, 2010 Author Share Posted June 29, 2010 Wow, man you are to much of a help! Everything is working well I just have ONE more thing to ask Is there a way I can make it so there is no scroll from left to right and if the line fills up it will continue on the line under it? Link to comment Share on other sites More sharing options...
UEZ Posted June 29, 2010 Share Posted June 29, 2010 I don't know whether you mean this:remove $WS_HSCROLL from line $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY).BR,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
foolet Posted June 30, 2010 Author Share Posted June 30, 2010 Thanks so much I have a question. How come everytime a run this at least 1 line will stay out of order :06-29-2010 20:23:05 Base: Got window event: origin=(112, 12) size=(800, 600) title="Window" !undecorated !fixed_size !fullscreen !foreground !minimized open !cursor_hidden icon:window.ico cursor:window.cur absolute :06-29-2010 20:19:40 Loader: starting bulk load of block 'StartWindow' As you can see 20:19:40 is not the latest in the log file. This always happens some line will stray out of order and stay out of order messing up the viewing of the log. Link to comment Share on other sites More sharing options...
UEZ Posted June 30, 2010 Share Posted June 30, 2010 Indeed, there is something going wrong... Found the problem -> forgot to erase the variable $new_line. Code update in post#3 Sorry, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
KaFu Posted June 30, 2010 Share Posted June 30, 2010 From a performance point of view, wouldn't it be better to wrap the function in a FileGetSize() check? Global $nFilesize, $nFilesize_new ;.... $nFilesize_new = FileGetSize($File) if $nFilesize < $nFilesize_new Then $nFilesize = $nFilesize_new ;.... $cl_new = _FileCountLines($File) If $cl < $cl_new Then ;.... endif OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
UEZ Posted June 30, 2010 Share Posted June 30, 2010 Good idea KaFu! If you use a more frequent check of the file it is better to check the file size instead using _FileCountLines() which is reading the complete file to enumerate the lines! Updated my post#3 again! BR, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
KaFu Posted June 30, 2010 Share Posted June 30, 2010 (edited) Hmmm, thinking about this, wouldn't it even be better not to clear the edit, but use the difference in size ($fs_new - $fs) to performa a FileSetPos() operation instead to move the read pointer to the new content and then do a FileReadLine() loop for new lines only? But I'm not quite sure if FileReadLine() works correctly in conjunction with FileSetPos() . Edit: The FileOpen() handle prevented me to write to the log via notepad... I'm not quite sure if this wouldn't be true for other programs too, thus I think it's better to close the handle once the data has been received. Of course this works only if new data is only appended to the log. expandcollapse popup;Coded by UEZ Build 2010-06-30, tweaked by KaFu ;-) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $iMemo, $new_line $width = 1024 $height = 600 $hGUI = GUICreate("Realtime Log Reader by UEZ 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST) $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY) GUICtrlSetLimit(-1, 0x7FFFFFFF) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then $file = $CmdLine[1] Else ;$file = @WindowsDir & "\WindowsUpdate.log" $file = @ScriptDir & "\test.log" EndIf $hFile = FileOpen($file) $txt = FileRead($hFile) GUICtrlSetData($iMemo, $txt, 1) _GUICtrlEdit_LineScroll($iMemo, 1, 0xfffffff) FileClose($hFile) $fs = FileGetSize($file) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While Sleep(1000) $fs_new = FileGetSize($file) If $fs < $fs_new Then $hFile = FileOpen($file,128) ConsoleWrite($fs_new - $fs & @crlf) FileSetPos($hFile, -($fs_new - $fs), 2) $new_line = FileRead($hFile) FileClose($hFile) GUICtrlSetData($iMemo, $new_line, 1) $fs = $fs_new EndIf WEnd Func _Exit() GUIDelete($hGUI) Exit EndFunc ;==>_Exit Edited June 30, 2010 by KaFu jugador 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
foolet Posted June 30, 2010 Author Share Posted June 30, 2010 May I have sex with both of you? Damn you guys are the best. 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