Jump to content
Sign in to follow this  

not able to capture returncode for ping

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.

Func pingCheck($system_name)
    ;$system_name = "sinra09-lod1"
    $command = @SystemDir&"\ping.exe -n 1 "& $system_name & " >nul: 2>nul:"
    Local $iReturn = RunWait($command)
    if $iReturn = 0 then
        Return True
        Return False

Please suggest..

Edited by ur

Share this post

Link to post
Share on other sites

Thanks @jguinch,

I am using Ping() function now.


Func waitForUp($systemname)
    for $iCount = 1 to 10
        if waitForSystem($systemname) Then
            return True
            $iCount = $iCount + 1
    return False

Func waitForSystem($systemname)
    Local $iPing = Ping($systemname)
    if $iPing>0 then
        return True
        Return False


Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By argumentum
      The file is now at 
      I added a WOL, tidy up, and moved the file to the uploads section of the forum.
      Suggestions are always mostly welcomed  
    • By argumentum
      In the ZIP is the code and the compiled script.
      This is yet another ping the LAN utility.
      Is quite fast, as gathering the info. is forked.
      The Save Note, saves a note for the given MAC ( you may find it handy )
      The Save MACs, saves the listview to an INI file that can be later use for the WakeOnLAN
      Right click will bring a context menu to do stuff. DClick will refresh the Ping.
      That's it. Comes in handy to have in the USB toolbox  
    • By hcI
      Hello everyone !
      While writing a sample of code to test ping to my internet box, I got stuck..
      While the code is Pinging with let say.. 5000ms of timeout, I need to update a progress bar from 0 to 5000 ms at the same time but I don't know how could I do this..
      Is there a way or something that could get around the pause of the ping like in InetGet -> InetGetInfo?
    • By AlexFing17
      i want a script that
      "on the beginning of the program it pings to check if there is internet connectivity.
      if there is internet connectivity
      then it executes my code
      else if there is no internet it waits at background to detected internet connectivity then executes my code."
      Is this possible

    • By tk1
      Is there a way, preferably natively within AutoIt, to replicate:
      ping -i 2 <nearby_IP>
      The ping() function only has an option to set the timeout, but I want to set the TTL to 2 instead.
  • Create New...