Jump to content

RUN Many commands at once


 Share

Recommended Posts

How can I run many commands at the same time...

Lets say I need to ping 6 hosts at once, something like:

$var1 = Ping("www.AutoItScript.com",250)
$var2 = Ping("google.com",150)
$var3 = Ping("gadzila.com",100)
$var4 = Ping("yahoo.com",50)
$var5 = Ping("enysite.com",100)
$var6 = Ping("sexycompany.org",200)

But this this script will run one PING after another, but how can i run them all at the same time and get result ?

Edited by Enforcer
[RU] Zone
Link to comment
Share on other sites

You can use a workaround by using the Run command and executing the windows build-in ping command. Here you can start multiple Run commands at once.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can use a workaround by using the Run command and executing the windows build-in ping command. Here you can start multiple Run commands at once.

Br,

UEZ

#include<Array.au3>
Global $Ping[6] = ["ConsoleWrite(Ping('www.AutoItScript.com',250))", _
"ConsoleWrite(Ping('google.com',150))", _
"ConsoleWrite(Ping('gadzila.com',100))", _
"ConsoleWrite(Ping('yahoo.com',50))", _
"ConsoleWrite(Ping('enysite.com',100))", _
"ConsoleWrite(Ping('sexycompany.org',200))"], $Ret[6], $RetPing[6], $I
For $I = 0 To UBound($Ping) -1
$Ret[$I] = Run(@AutoItExe & ' /AutoIt3ExecuteLine "'&$Ping[$I]&'"',"","", 0x8); exe used needs to be console app
While 1
$RetPing[$I] = StdoutRead($Ret[$I])
If @error Then ExitLoop
WEnd
Next

_ArrayDisplay($RetPing)

Posted Image

Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

Try this:

#include <Array.au3>
;aSites = site, ping timeout, pid of run, ping status
Global $aSites[6][4] = [ _
                                            ["www.AutoItScript.com", 250], _
                                            ["google.com", 150], _
                                            ["gadzila.com", 100], _
                                            ["yahoo.com", 50], _
                                            ["enysite.com", 100], _
                                            ["sexycompany.org", 200] _
                                            ]

$aResult = Ping_Hosts($aSites)
_ArrayDisplay($aResult)
Exit

Func Ping_Hosts(ByRef $aSites) ;coded by UEZ 2011
    Local $i, $ub, $counter
    For $i = 0 To UBound($aSites) - 1
        $aSites[$i][2] = Run(@ComSpec & " /c ping.exe " & $aSites[$i][0] & " -n 1 -w " & $aSites[$i][1], "", @SW_HIDE, 8)
        $aSites[$i][3] = False
    Next

     $i = UBound($aSites) - 1
     $ub = UBound($aSites)
     $counter = 0
    While Sleep(30)
        If StringInStr(StdoutRead($aSites[$i][2]), "Reply from") Then $aSites[$i][3] = True ;change "Reply from"to appropriate language
        If Not ProcessExists($aSites[$i][2]) And $aSites[$i][2] > 0 Then
            $aSites[$i][2] = 0
            $counter += 1
        EndIf
        If $counter = $ub Then ExitLoop
        $i = Mod($i + 1, $ub)
    WEnd
    Return $aSites
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try this:

#include <Array.au3>
;aSites = site, ping timeout, pid of run, ping status
Global $aSites[6][4] = [ _
                                            ["www.AutoItScript.com", 250], _
                                            ["google.com", 150], _
                                            ["gadzila.com", 100], _
                                            ["yahoo.com", 50], _
                                            ["enysite.com", 100], _
                                            ["sexycompany.org", 200] _
                                            ]

$aResult = Ping_Hosts($aSites)
_ArrayDisplay($aResult)
Exit

Func Ping_Hosts(ByRef $aSites) ;coded by UEZ 2011
    Local $i, $ub, $counter
    For $i = 0 To UBound($aSites) - 1
        $aSites[$i][2] = Run(@ComSpec & " /c ping.exe " & $aSites[$i][0] & " -n 1 -w " & $aSites[$i][1], "", @SW_HIDE, 8)
        $aSites[$i][3] = False
    Next

     $i = UBound($aSites) - 1
     $ub = UBound($aSites)
     $counter = 0
    While Sleep(30)
        If StringInStr(StdoutRead($aSites[$i][2]), "Reply from") Then $aSites[$i][3] = True ;change "Reply from"to appropriate language
        If Not ProcessExists($aSites[$i][2]) And $aSites[$i][2] > 0 Then
            $aSites[$i][2] = 0
            $counter += 1
        EndIf
        If $counter = $ub Then ExitLoop
        $i = Mod($i + 1, $ub)
    WEnd
    Return $aSites
EndFunc

Br,

UEZ

That's more or less what I had in mind, launching a whole bunch of processes but then I realized the autoitexe needs to be a console app. :D
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...