Enforcer Posted December 8, 2011 Posted December 8, 2011 (edited) 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 December 8, 2011 by Enforcer [RU] Zone
somdcomputerguy Posted December 8, 2011 Posted December 8, 2011 You can't. AutoIt is not multi-threaded. This topic has been discussed here many times. Search and see. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
UEZ Posted December 8, 2011 Posted December 8, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Skitty Posted December 8, 2011 Posted December 8, 2011 (edited) 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) Edited December 8, 2011 by THAT1ANONYMOUSEDUDE
UEZ Posted December 8, 2011 Posted December 8, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Skitty Posted December 8, 2011 Posted December 8, 2011 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.
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