ur Posted February 20, 2017 Posted February 20, 2017 (edited) I want to check whether machine is up or not after we poweron a VM. So to check that, I am using ping. With the below command, when we run it, it will capture the value success or not with the errorlevel. ping -n 1 sinra09-lod11 >nul: 2>nul: so we can track the return code back using below. echo %errorlevel% So it is able to return the 1 when it is failure and 0 when it is success. But when I convert the above commands to AutoIT, the return code is always giving 0 even on failure. MsgBox(0,pingCheck("sinra09-lod11"),"sinra09-lod11") Func pingCheck($system_name) ;$system_name = "sinra09-lod1" $command = @SystemDir&"\ping.exe -n 1 "& $system_name & " >nul: 2>nul:" ConsoleWrite($command) Local $iReturn = RunWait($command) ;MsgBox(0,$system_name,$iReturn) ConsoleWrite($iReturn) if $iReturn = 0 then Return True Else Return False EndIf EndFunc Please suggest.. Edited February 20, 2017 by ur
jguinch Posted February 20, 2017 Posted February 20, 2017 You cannot use %errorlevel% with the Ping command for this Why don't you use the AutoIt Ping() function ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
jguinch Posted February 20, 2017 Posted February 20, 2017 (edited) To work with the %errorlevel% value, change your command by this one : @ComSpec & ' /c ping ' & $system_name & ' -n 1 | find "TTL" Edited February 20, 2017 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
ur Posted February 20, 2017 Author Posted February 20, 2017 Thanks @jguinch, I am using Ping() function now. MsgBox(0,waitForUp("win10x64"),"") Func waitForUp($systemname) for $iCount = 1 to 10 if waitForSystem($systemname) Then return True Else $iCount = $iCount + 1 Sleep(5000) EndIf Next MsgBox(0,"",$iCount) return False EndFunc Func waitForSystem($systemname) Local $iPing = Ping($systemname) if $iPing>0 then return True Else Return False EndIf EndFunc
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