astrax Posted March 24, 2009 Share Posted March 24, 2009 Hi, my code is below. My intention was to do a ping by clicking the button $Ping_Bnt and capture the stdout into a text box $PING_TXT and break out of a loop and then will be able to click the button to start over again. Can anyone please modify so that i'm able to do so? I can ping only once and my GUI is locked because the loop is still running. Please help. Greatly appreciated While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @Error = -1 Then ExitLoop GUICtrlSetData($PING_TXT, $lineout, 1) WEnd EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 24, 2009 Moderators Share Posted March 24, 2009 astrax,Just add another ExitLoop after you have set $PING_TXT:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @error = -1 Then ExitLoop GUICtrlSetData($PING_TXT, $lineout, 1) ExitLoop ; <<<<<<<<<<<<<<<<<<<<< Added WEnd EndSwitch WEndThat way you exit the inner While...WEnd loop and reenter the outer While...WEnd loop ready for another button press.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
astrax Posted March 24, 2009 Author Share Posted March 24, 2009 (edited) astrax, Just add another ExitLoop after you have set $PING_TXT:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @error = -1 Then ExitLoop GUICtrlSetData($PING_TXT, $lineout, 1) ExitLoop; <<<<<<<<<<<<<<<<<<<<< Added WEnd EndSwitch WEnd That way you exit the inner While...WEnd loop and reenter the outer While...WEnd loop ready for another button press. M23 Putting the EndLoop where you said will not work unless i set a sleep time so the ping can catch up. The while loop keep looping so it picks up immediately. You can run the script to see what i mean. Try testing with a non working host like the one that has ping blocked. You won't be able to see all the result because the ping takes longer and the EndLoop already executed expandcollapse popup#include <GuiConstantsEx.au3> #include <ClipBoard.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> #include <Constants.au3> Opt('MustDeclareVars', 1) Global $PING_TXT, $lineout, $ping _Main() Func _Main() Local $Ping_Bnt GUICreate("Text", 382, 280) $PING_TXT = GUICtrlCreateEdit("", 15, 10, 352, 200) $Ping_Bnt = GUICtrlCreateButton("Ping", 15, 220, 50) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 ;sleep(3000) $lineout = StdoutRead($ping) If @Error = -1 Then ExitLoop GUICtrlSetData($PING_TXT, $lineout, 1) ;sleep(6000) ;ExitLoop WEnd EndSwitch WEnd EndFunc;==>_Main Edited March 24, 2009 by astrax Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 24, 2009 Moderators Share Posted March 24, 2009 astrax, Apologies - my misunderstanding. How about checking that something has been returned and then exiting:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @error = -1 Then ExitLoop If $lineout <> "" Then GUICtrlSetData($PING_TXT, $lineout, 1) ExitLoop EndIf WEnd EndSwitch WEnd M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
astrax Posted March 24, 2009 Author Share Posted March 24, 2009 (edited) This is where i'm stuck, i don't know what to do. I need all the ping stdout entries in the text box wether ping success or ping fail. I need to break the loop so i can ping again astrax, Apologies - my misunderstanding. How about checking that something has been returned and then exiting:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @error = -1 Then ExitLoop If $lineout <> "" Then GUICtrlSetData($PING_TXT, $lineout, 1) ExitLoop EndIf WEnd EndSwitch WEnd M23 Edited March 24, 2009 by astrax Link to comment Share on other sites More sharing options...
MrMitchell Posted March 24, 2009 Share Posted March 24, 2009 (edited) I just changed your one line: If @Error = -1 Then ExitLoop To: If @Error <> 0 Then ExitLoop Worked fine for me after that...still trying to figure out why though lol Edit: Added info... ...Maybe because StdOutRead sets @error to non-zero when EOF is reached Edited March 24, 2009 by MrMitchell Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 24, 2009 Share Posted March 24, 2009 Hi, my code is below. My intention was to do a ping by clicking the button $Ping_Bnt and capture the stdout into a text box $PING_TXT and break out of a loop and then will be able to click the button to start over again. Can anyone please modify so that i'm able to do so? I can ping only once and my GUI is locked because the loop is still running. Please help. Greatly appreciated: While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ping_Bnt $ping = Run(@ComSpec & " /c ping google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $lineout = StdoutRead($ping) If @Error = -1 Then ExitLoop GUICtrlSetData($PING_TXT, $lineout, 1) WEnd EndSwitch WEnd Please post code in code tags so it is readable. You shouldn't be testing "If @error = -1". The help file under StdOutRead() says: Failure: Sets @error to non-zero if EOF is reached, STDOUT was not redirected for the process or other error. Just use: $lineout = StdoutRead($ping) If @Error Then ExitLoop Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
astrax Posted March 24, 2009 Author Share Posted March 24, 2009 You guys are AWSOME!!! Thank you so much for making it work.. I've been scratching my head for hours. Thank you so much all for trying to help me one way or another. Please post code in code tags so it is readable. You shouldn't be testing "If @error = -1". The help file under StdOutRead() says: Just use: $lineout = StdoutRead($ping) If @Error Then ExitLoop 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