#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include Global $iSpawnChildren = 3 ; Control how many children processes to spawn. Want to crash your computer? Run 50 :) Global Enum $CHILD_PID, $CHILD_MSG, $CHILD_LASTMSG, $CHILD_MAX ; Just so we don't have to remember indexes Global $aChildren[$iSpawnChildren][$CHILD_MAX] ; Array to hold our child information OnAutoItExitRegister('__Exit') ; Close any open children ; Main loop ; Spawn child in any slots that are open _CheckForChildrenToSpawn() While 1 ; Read any StdOut messages and check for 'important' ones _CheckForMsgsFromChildren() ; Avoid 100% cpu Sleep(10) WEnd Func _CheckForChildrenToSpawn() Local $iSpawned = 0 ; Not really needed, just how many new ones were spawned this check ; Loop through each available child slot For $iChild = 0 To UBound($aChildren) - 1 $aChildren[$iChild][$CHILD_PID] = Run('Child.au3 ' & $iChild, '', @SW_HIDE, $STDERR_MERGED + $RUN_CREATE_NEW_CONSOLE) If @error Or $aChildren[$iChild][$CHILD_PID] = 0 Then MsgBox(0, "error", "Error for run: " & @error) $aChildren[$iChild][$CHILD_PID] = 0 ContinueLoop EndIf Sleep(5000) ; problem here ! ; Just a little sleep so you don't crash your system when spawning a lot of children Sleep(50) ; Reset values for this child $aChildren[$iChild][$CHILD_MSG] = '' $aChildren[$iChild][$CHILD_LASTMSG] = TimerInit() $iSpawned += 1 Next Return SetError(0, 0, $iSpawned) EndFunc ;==>_CheckForChildrenToSpawn Func _CheckForMsgsFromChildren($iIndexOverride = Default) Local $aSplit, $aBetween Local $iMin = 0, $iMax = UBound($aChildren) - 1 ; Allow checking a specific child, used for when the child process doesn't exist any more, get any remaning messages If Not $iIndexOverride = Default Then $iMin = $iIndexOverride $iMax = $iIndexOverride EndIf ; Loop through each process For $iChild = $iMin To $iMax ; Get any messages $aChildren[$iChild][$CHILD_MSG] = StdoutRead($aChildren[$iChild][$CHILD_PID]) If @error Then ; Just most likely means that EOF was reached, since we're checking so often ContinueLoop EndIf If $aChildren[$iChild][$CHILD_MSG] == '' Then ContinueLoop ; No message ; Get a message to output in the main script that was logged between as [] in the child $aBetween = _StringBetween($aChildren[$iChild][$CHILD_MSG], '[', ']') If @error Then ContinueLoop __cLog($aBetween[0]) Sleep(5000) ; problem here ! $aChildren[$iChild][$CHILD_MSG] = '' $aChildren[$iChild][$CHILD_LASTMSG] = TimerInit() Next EndFunc ;==>_CheckForMsgsFromChildren Func __Exit() ; Close any remaining open processes For $iChild = 0 To UBound($aChildren) - 1 ProcessClose($aChildren[$iChild][$CHILD_PID]) Next Exit EndFunc ;==>__Exit Func __cLog($sMsg) ConsoleWrite($sMsg & @CRLF) EndFunc ;==>__cLog