Jump to content

Yet another simple multiprocess

Recommended Posts


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')

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 "
    Local $sPID = Run(@ComSpec & $sShowhide & $sCommand, "", $sWindow, $STDERR_CHILD + $STDOUT_CHILD), _
    Switch $sWait
        Case -1
            $sResult = ProcessWaitClose($sPID)
        Case 0.01 To 999999999999999999
            $sResult = ProcessWaitClose($sPID, $sWait)
    Local $sReturn[2]
    $sReturn[0] = $sResult
    $sReturn[1] = $sPID
    Return $sReturn
EndFunc   ;==>rundos
Edited by TouchOdeath
added stdout reading, and return is now array

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.