JohnCleese Posted August 13, 2009 Share Posted August 13, 2009 (edited) Hello,Can somebody give me some insight on how to keep my script running continuously.E.g, I have some hotkeys set to perform bat commands. But I don't want it to automatically close after they are performed.Edit: Actually they don't even run because they are all functions and get skipped over. So the script closes almost instantly. Edited August 13, 2009 by JohnCleese "I find it rather easy to portray a businessman. Being bland, rather cruel and incompetent comes naturally to me." Link to comment Share on other sites More sharing options...
omikron48 Posted August 13, 2009 Share Posted August 13, 2009 Just put this in the last few lines of your script, or at the last part of whatever is the main part of the script: While(1) WEnd or this: (will make you script run for a day, 24 hours) Sleep(86400000) Link to comment Share on other sites More sharing options...
JohnCleese Posted August 13, 2009 Author Share Posted August 13, 2009 Just put this in the last few lines of your script, or at the last part of whatever is the main part of the script: While(1) WEnd This seems to be working well, but I don't know if it will break as I add more. Anyways, thank you very much this seems to be just what I needed. >_< "I find it rather easy to portray a businessman. Being bland, rather cruel and incompetent comes naturally to me." Link to comment Share on other sites More sharing options...
omikron48 Posted August 13, 2009 Share Posted August 13, 2009 Just make sure either that sleep or while loop is the last thing to execute in your script. If you want to add something, do it before that, otherwise it will not execute since the parser will not pass through past the while loop or sleep. Link to comment Share on other sites More sharing options...
cal Posted August 14, 2009 Share Posted August 14, 2009 A lot of my scripts are to add functions to other programs. The following is my template in these cases. I use the script instead of calling the program directly and have the script call it. I then add whatever hotkeys and other stuff to watch for in the script. This also exits the script after the program closes. BTW. I've always put a sleep in there with the while statement. I don't know if that's needed or not. I've always assumed that a sleep line would use less processing power then always checking a while statement that can never change. also always make sure you have some way of exiting the script. Either my method here or hotkey. Unless of course the intention is to always run as long as the computer is on. I have a couple that do that too. expandcollapse popup; ----- run some program If Not WinExists(' program win title ') Then Run('program path exe', '') WinWaitActive('prog name') Sleep(2000) Else WinSetState('program ', '', @SW_SHOW) ; if in tray, this will make it show. WinActivate('program ', '') ; I've got some apss that need this too to come into focus. EndIf are_we_done('exe of program that shows in tskmgr', 5) ; exe of prog, timeout in sec ; setup whatever else you need to interact with the program. ; at end of script. While 1 Sleep(30000) WEnd ; watch for program close. Func are_we_done($process_name2,$timout_value) Global $process_name = '' $process_name = $process_name2 AdlibEnable("are_we_done_2", $timout_value * 1000) EndFunc ;==>are_we_done Func are_we_done_2() $pid = ProcessExists($process_name) If $pid == 0 Then Exit EndFunc LePucco 1 Link to comment Share on other sites More sharing options...
omikron48 Posted August 14, 2009 Share Posted August 14, 2009 (edited) Yeah. You should insert a Sleep there in between my While(1) loop, to skimp on unnecessary processing by your script. Personally, I just use a long Sleep command as my main executing script when I want to make a HotKey script that I want to stick around for a while. Edited August 14, 2009 by omikron48 Link to comment Share on other sites More sharing options...
Valuater Posted August 14, 2009 Share Posted August 14, 2009 Remember guys, if you are waiting for an input with GUIGetMsg() it will not work correctly. Also when using GUIGetMsg() there is no sleep() needed. 8) 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