Jump to content

Recommended Posts

Posted (edited)

I've been looking for a Multithread/Multiprocess, doesnt matter to me as long as you can run stuff simultaneously.  Before anyone chimes in please read this:  https://www.autoitscript.com/trac/autoit/wiki/AutoItNotOnToDoList

This is Multiprocess NOT Multithread.  Simple yet elegant.  Also it includes a good rundos function.

#include <Misc.au3>
#include <AutoItConstants.au3>

Switch $CmdLine[0]
    Case 0
        _Singleton(@ScriptName, 0) ;prevent script from opening twice by accident
    Case 1
        Switch $CmdLine[1] ;run whatever code you want here and exit, but not exiting the main program
            Case "scenario1"
                MsgBox(0,'1','process 2')
            Case "scenario2"
                MsgBox(0,'2','process 3')
        EndSwitch
        Exit
EndSwitch

rundos("""" & @ScriptName & """" & " scenario1")
rundos("""" & @ScriptName & """" & " scenario2")
MsgBox(0,'3','process 1, this is your normal program')
;code goes here

Func rundos($sCommand, $sWait = 0, $sWindow = @SW_HIDE)
    Local $sShowhide
    Switch $sWindow
        Case 5 ;@sw_show
            $sShowhide = " /k "
        Case 0 ;@SW_HIDE
            $sShowhide = " /c "
        case Else
            $sShowhide = " /k "
    EndSwitch
    Local $sPID = Run(@ComSpec & $sShowhide & $sCommand, "", $sWindow, $STDERR_CHILD + $STDOUT_CHILD), _
            $sResult
    Switch $sWait
        Case -1
            $sResult = ProcessWaitClose($sPID)
        Case 0.01 To 999999999999999999
            $sResult = ProcessWaitClose($sPID, $sWait)
    EndSwitch
    Local $sReturn[2]
    $sReturn[0] = $sResult
    $sReturn[1] = $sPID
    Return $sReturn
EndFunc   ;==>rundos
Edited by TouchOdeath
added stdout reading, and return is now array

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
  • Recently Browsing   0 members

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