Jump to content

not able to capture returncode for ping


ur
 Share

Recommended Posts

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 by ur
Link to comment
Share on other sites

To work with the %errorlevel% value, change your command by this one :

@ComSpec & ' /c ping ' & $system_name & ' -n 1 | find "TTL"

 

 

Edited by jguinch
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...