pauleffect Posted February 7, 2014 Share Posted February 7, 2014 Hello guys. I have a problem. I have a Ui with multiple buttons. One of those buttons starts a script. Another (should) closes it. The problem is that the 2nd script is an infinite loop. Thus, freezing my ui and utterly defeating the close button. One idea is to compile the 2nd script and run it silently - no tray icon, hidden, etc. But it's my own idea, so it must be a better way. I have searched for solutions but .... Thank you for your time. Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 Use oneventmode AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 (edited) I am... Opt("GUIOnEventMode", 1) Edited February 7, 2014 by pauleffect Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 Post a reproducer of your problem. Does not have to be your script, just recreate the issue. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Unc3nZureD Posted February 7, 2014 Share Posted February 7, 2014 Adlibregister ? Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 (edited) Well, long story short - This is the main script Opt("GUIOnEventMode", 1) $Gui = GUICreate("Gui",500,700,-1,-1,$WS_POPUP,-1) bla-bla-bla GUISetState(@SW_SHOW,$Gui) while 1 sleep(1) wend Func button_Connect() ShellExecute(@scriptdir&"\serverapp_nowin.jar") ;~ #include "data\dav_hotkey.au3" Run("srv.exe") $toggle = true Endfunc Func button_Dissconect() ProcessClose("javaw.exe") ProcessClose("srv.exe") $toggle = false Endfunc the second is a file reading loop and keystrokes sender. while $toggle ..... when i try to close the script (or minimize, close the ui, etc) it does nothing. It's kind of logical, being stuck in the second loop... ___ Adlibregister i'll look into it Edited February 7, 2014 by pauleffect Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 You have not set any events on GUI or controls (of which their are none) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 You have not set any events on GUI or controls (of which their are none) GUICtrlSetOnEvent($btnMin, "button_min") GUICtrlSetOnEvent($btnClose, "button_Close") GUICtrlSetOnEvent($btnStoreip, "button_Storeip") GUICtrlSetOnEvent($btnConnect, "button_Connect") GUICtrlSetOnEvent($btnDisconnect, "button_Dissconect") GUICtrlSetOnEvent($btnStartV, "button_startV") GUICtrlSetOnEvent($btnStopV, "button_stopV") GUICtrlSetOnEvent($btnHelp, "button_help") I thought it was understood i did, considering it starts the 2nd loop... Sorry, my bad, forgot to mention Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 If you cannot be bothered to show runnable script, just say so, and I wont bother you any further. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 I don't see the point. it's nothing wrong with the code. It acts exactly as it should. I have a problem I don't know how to fix . Exiting a loop. With a button click. While that loop is running. Thought there was a generic way, smthing I was missing. I see that this is not the case. I will try harder and... hope for the best. Best wishes and thank you for your time! Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 No there is a generic way, which you said you're doing but you must be doing something wrong, so whatever that something is, it cannot be known without seeing the exact structure of your code. I can tell you though, that your second script has nothing to do with your first not closing. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 i see, thank you for your time.i'll manage somehow. Link to comment Share on other sites More sharing options...
ZacUSNYR Posted February 7, 2014 Share Posted February 7, 2014 John is correct, your second script has nothing to do with the first one. You're putting a halt in your first script. Are you using RunWait? Are you doing a loop to check for the running process? How do you get out of a loop, look in the help file for ExitLoop. The concept is proper, your execution is what's wrong. #NoTrayIcon #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Script 2", 200, 50) GUISetBkColor($COLOR_BLACK, $hGUI) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hGUI_StatusLabel = GUICtrlCreateLabel("", 55, 15, 125, 20) GUICtrlSetFont(-1, 14, 800, 0, "Arial", 5) GUICtrlSetColor(-1, $COLOR_RED) GUISetState(@SW_SHOW, $hGUI) While 1 GUICtrlSetData($hGUI_StatusLabel, _CurrentTime()) Sleep(10) WEnd Func _CurrentTime() Return (@HOUR & Chr(58) & @MIN & Chr(58) & @SEC & Chr(46) & @MSEC) EndFunc Func _Exit() Exit EndFunc Compile that script, call it script2.exe. Then run this script. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iPID Global Const $LAUNCH_SCRIPT = @ScriptDir & "\Script2.exe" Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Launcher", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hGUI_LabelPID = GUICtrlCreateLabel("Not Running", 5, 5, 190, 25) GUICtrlSetFont(-1, 14, 800, 0, "Arial", 5) $hGUI_ButtonLaunch = GUICtrlCreateButton("Launch Script", 10, 50, 75, 25) GUICtrlSetOnEvent(-1, "_BUTTON_LaunchScript") $hGUI_ButtonStop = GUICtrlCreateButton("Stop Script", 115, 50, 75, 25) GUICtrlSetOnEvent(-1, "_BUTTON_StopScript") GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(10) WEnd Func _BUTTON_LaunchScript() If FileExists($LAUNCH_SCRIPT) Then $iPID = Run($LAUNCH_SCRIPT, @ScriptDir) If Not @error Then GUICtrlSetData($hGUI_LabelPID, "Running (PID): " & $iPID) GUICtrlSetState($hGUI_ButtonLaunch, $GUI_DISABLE) GUICtrlSetState($hGUI_ButtonStop, $GUI_ENABLE) EndIf Else MsgBox(0, "File Not Found", $LAUNCH_SCRIPT & " NOT FOUND!") _Exit() EndIf EndFunc Func _BUTTON_StopScript() If ProcessExists($iPID) Then ProcessClose($iPID) GUICtrlSetData($hGUI_LabelPID, "Not Running") GUICtrlSetState($hGUI_ButtonLaunch, $GUI_ENABLE) GUICtrlSetState($hGUI_ButtonStop, $GUI_DISABLE) EndFunc Func _Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
pauleffect Posted February 7, 2014 Author Share Posted February 7, 2014 oh, i already got it to work like this (main ui script + compiled exe). i was wondering if there was a way to compile a single exe like this: generate UI ----> click button ------->start script2 (contains infinite loop) click button 2 -----> close script2 I really apreciate your support and answers and I feel like a douche for wasting your time. Link to comment Share on other sites More sharing options...
ZacUSNYR Posted February 7, 2014 Share Posted February 7, 2014 (edited) I come here to learn. Helping out others is learning for myself. So it's not a waste of time at all. There are a few options you have, if you don't need the first script to be responsive, you can just interrupt the function. The button, when using OnEvent, will interrupt a function. So you could set a flag to send the interrupt to get yourself out of the loop. Another option is to use the CmdLine[] array - you could do Run(@ScriptFullPath & " /somethingtodo") - the help file includes some information under Command Line Parameters. If $CmdLine[0] > 0 Then If StringInStr($CmdLine[1], "/somethingtodo") Then _RunThisFunction()) Exit EndIf Edited February 7, 2014 by ZacUSNYR Link to comment Share on other sites More sharing options...
BlackDawn187 Posted February 8, 2014 Share Posted February 8, 2014 In your situation, I would declare a ridiculous Hotkey in your second script, That when used exits the script. Then in your first script, Set it so that when your kill button is pressed it sends your ridiculous hotkey combination. Thus, Bypassing any chance of accidentally exiting the script. Ofcourse, If your second script is compiled you can simple initiate a ProcessClose on it. Link to comment Share on other sites More sharing options...
nullschritt Posted February 8, 2014 Share Posted February 8, 2014 I come here to learn. Helping out others is learning for myself. So it's not a waste of time at all. There are a few options you have, if you don't need the first script to be responsive, you can just interrupt the function. The button, when using OnEvent, will interrupt a function. So you could set a flag to send the interrupt to get yourself out of the loop. Another option is to use the CmdLine[] array - you could do Run(@ScriptFullPath & " /somethingtodo") - the help file includes some information under Command Line Parameters. If $CmdLine[0] > 0 Then If StringInStr($CmdLine[1], "/somethingtodo") Then _RunThisFunction()) Exit EndIf Use this method, and when start is pressed use run() to execute your process, and get the PID of the new process, when you push stop, kill the PID. If you need your scripts to communicate you have to use IPC. Link to comment Share on other sites More sharing options...
pauleffect Posted February 8, 2014 Author Share Posted February 8, 2014 Use this method, and when start is pressed use run() to execute your process, and get the PID of the new process, when you push stop, kill the PID. If you need your scripts to communicate you have to use IPC. I'm going to try everything you guys posted! Thanks for the support! 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