grimmlock Posted January 14, 2013 Posted January 14, 2013 I am trying to get a ping to continuously run until it the pings reply then show a msgbox that it is online. When I run this it just sits "idle" and does not seem to be doing anything Here is what I have Func _local2() Local $PID = ping("192.168.27.172") If $PID = 0 Then Do ping("192.168.27.172") Until $PID = 1 Msgbox(0, "", "Online") Else EndIf EndFunc Thanks Grimm Thanks Grimm
Moderators Melba23 Posted January 14, 2013 Moderators Posted January 14, 2013 grimmlock,Two points on that code- 1. When do you ever change the value of $PID? If it never changes than you will never exit the Do...Until loop.- 2. Why do yo think Ping returns a PID? When I look in the Help file it talks about returning the "the roundtrip-time in milliseconds.Have a think about those and see if you can come up with a better snippet yourself. 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
funkey Posted January 14, 2013 Posted January 14, 2013 You have to set the variable $PID every time in the loop. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
grimmlock Posted January 14, 2013 Author Posted January 14, 2013 Melba hello again 1) If I ping that I ip address and the computer is turned off it does return a 0 and if the computer is on the it returns a 1. That is why I have it set so that if the $PID returns a 0 (which equals off) to do a ping until the return value is a 1 which means the computer is online and is pinging. 2) That is why I think a ping returns a PID. And I know PID might be used for some other reason in Autoit but for me is was a simple variable I could attach to the ping. Should I be using $var instead of $PID, is it because $PID is used to define something else? Thanks Grimm Thanks Grimm
grimmlock Posted January 14, 2013 Author Posted January 14, 2013 I think I figured out where my issue is thanks Grimm Thanks Grimm
Moderators Melba23 Posted January 14, 2013 Moderators Posted January 14, 2013 grimmlock,PID is more normally used as shorthand for "Process ID" - you get that returned when you start a process using Run and it is a unique number used to identify that particular process. There is no reason why you should not use $PID as your variable name - but it could lead to confusion, as evidenced above. But returning to why the snippet is not working - you never update the value of $PID (or whatever you want to call it) as you check it - so the Until condition is never met. And if you get a return value from Ping in the loop, why do you think it will be 1? I think it is much more likely to be a positive value of some kind - I told you above what the Help file says the value will be. So you need to update $PID in the loop and set the condition to be less specific - something like this perhaps (untested):Func _local2() Local $PID = ping("192.168.27.172") If $PID = 0 Then ; Start the loop running until ping returns a value Do Sleep(10) ; Give the CPU a break ; Has ping returned a value? Until ping("192.168.27.172") <> 0 ; If yes then we get here Msgbox(0, "", "Online") Else EndIf EndFuncAll clear? 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
funkey Posted January 14, 2013 Posted January 14, 2013 _WaitForIP("192.168.27.172") Func _WaitForIP($sIP) Do Sleep(10) ; Give the CPU a break Until Ping($sIP) <> 0 MsgBox(0, $sIP, "Online") EndFunc ;==>_WaitForIP Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
grimmlock Posted January 14, 2013 Author Posted January 14, 2013 (edited) That makes more sense thanks all Grimm Well I was close Edited January 14, 2013 by grimmlock Thanks Grimm
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