Accension Posted September 17, 2010 Share Posted September 17, 2010 Having some trouble w/ this code. After a while it runs out of memory. I added a 100 ms delay but that only makes it run longer, but it still eventually runs out of memory. $input = "c:\Users\Admin\Scripts\Var\request.txt" $destination = "c:\Users\Admin\Scripts\Var\request2.txt" ; set esc hotkey HotKeySet("{ESC}", "Terminate") ; set delay between keys default: 5 ; 50 = telnet speed AutoItSetOption("SendKeyDelay",50) $file = "1" ; Iterates every new set of instructions While CheckInput($input,$file) ; Open putty session and login Run("C:\putty\putty.exe") WinWaitActive("[CLASS:PuTTYConfigBox]") Send("{TAB 4}{DOWN 2}{ENTER}") WinWaitActive("[CLASS:PuTTY]") Sleep(500) Send("speed{ENTER}") Sleep(500) Send("speed{ENTER}") Sleep(500) Send("{ENTER}") Sleep(1000) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop Send($line) WEnd FileMove($input,$destination,1) Sleep(2000) ; need time for the file to move Wend Func CheckInput($input,ByRef $file) $file = FileOpen($input, 0) While $file = -1 $file = FileOpen($input, 0) Sleep(100) WEnd Return 1 EndFunc Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 17, 2010 Share Posted September 17, 2010 You forgot to FileClose the handle. See FlieOpen and FileClose in the helpfile. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Accension Posted September 17, 2010 Author Share Posted September 17, 2010 You forgot to FileClose the handle. See FlieOpen and FileClose in the helpfile.I will try that, however, the program doesn't run out of memory while it's working, it actually runs out of memory when it's idle in that CheckInput function. (At least that is what I believe based on the behavior). Link to comment Share on other sites More sharing options...
Accension Posted September 17, 2010 Author Share Posted September 17, 2010 You forgot to FileClose the handle. See FlieOpen and FileClose in the helpfile. I set the fileclose, but I notice in task manager the program keeps getting larger and larger in memory expandcollapse popup$input = "c:\Users\Admin\Scripts\Var\request.txt" $destination = "c:\Users\Admin\Scripts\Var\request2.txt" ; set esc hotkey HotKeySet("{ESC}", "Terminate") ; set delay between keys default: 5 ; 50 = telnet speed AutoItSetOption("SendKeyDelay",50) $file = "1" ; Iterates every new set of instructions While CheckInput($input,$file) ; Open putty session and login Run("C:\putty\putty.exe") WinWaitActive("[CLASS:PuTTYConfigBox]") Send("{TAB 4}{DOWN 2}{ENTER}") WinWaitActive("[CLASS:PuTTY]") Sleep(500) Send("speed{ENTER}") Sleep(500) Send("speed{ENTER}") Sleep(500) Send("{ENTER}") Sleep(1000) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop Send($line) WEnd FileClose($file) FileMove($input,$destination,1) Sleep(2000) ; need time for the file to move Wend Func CheckInput($input,ByRef $file) $file = FileOpen($input, 0) While $file = -1 $file = FileOpen($input, 0) Sleep(100) WEnd FileClose $file Return 1 EndFunc Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
Accension Posted September 17, 2010 Author Share Posted September 17, 2010 Actually, I had to remove the fileclose inside CheckInput function otherwise I would not be able to open the file. This application is basically waiting for a file to exist, then opening it. 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