We help IT Professionals succeed at work.

A method to cue multiple script sequential execution.

mgjust
mgjust asked
on
Hello,
Is there a way to have scripts run sequentially with just one act of execution (pardon my jargon or lack thereof)? To be clear: Have a script execute only after the previous has finished?

Thanks,
MJ
Comment
Watch Question

Commented:
Well at the end of the script you can call the next script
if this is in widows batch you just need to put the commands in in the order you would type them out at the command prompt. if this does not help let me know and i can post a short example. it also might help if you posted a short example of what your trying to do.
BRONZE EXPERT
Commented:
http://www.tek-tips.com/faqs.cfm?fid=5755   onjShell.run

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).
Remarks
The Run method returns an integer. The Run method starts a program running in a new Windows process. You can have your script wait for the program to finish execution before continuing. This allows you to run scripts and programs synchronously. Environment variables within the argument strCommand are automatically expanded. If a file type has been properly registered to a particular program, calling run on a file of that type executes the program. For example, if Word is installed on your computer system, calling Run on a *.doc file starts Word and loads the document. The following table lists the available settings for intWindowStyle.



Commented:
a.py:
print 'a is running...'

b.py:
print 'b is running...'

run.bat:
@python a.py
@python b.py

cmd> run
a is running...
b is running...

In that example b.py will run only after a.py finished
SILVER EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, you can use a call to this VBS to wait for one or multiple batch files to finish:

'===================
'MUST BE RUN BY: START /WAIT RunAndWait.vbs script1.vbs script2.vbs
If WScript.Arguments.Count > 0 Then
      strWhileCondition = "Do Until "
      Set wshShell = CreateObject("WScript.Shell")
      For intArgNum = 0 To WScript.Arguments.Count - 1
            strCodeToExec = "Set objExec" & intArgNum & " = wshShell.Exec(""wscript.exe " & WScript.Arguments(intArgNum) & """)"
            Execute strCodeToExec
            If intArgNum < WScript.Arguments.Count - 1 Then
                  strWhileCondition = strWhileCondition & "objExec" & intArgNum & ".Status AND "
            Else
                  strWhileCondition = strWhileCondition & "objExec" & intArgNum & ".Status"
            End If
      Next
      strWhileCondition = strWhileCondition & VbCrLf & "WScript.Sleep 500" & VbCrLf & "Loop"
      'MsgBox strWhileCondition
      Execute strWhileCondition
End If
'===================

And you can use it in a batch file like this:

@echo off
start /wait RunAndWait.vbs file1.vbs file2.vbs file3.vbs
start /wait RunAndWait.vbs file4.vbs

Regards,

Rob.
SILVER EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Oh, that's for VBS Files...this should work for batches:

'===================
'MUST BE RUN BY: START /WAIT RunAndWait.vbs script1.bat script2.bat
If WScript.Arguments.Count > 0 Then
      strWhileCondition = "Do Until "
      Set wshShell = CreateObject("WScript.Shell")
      For intArgNum = 0 To WScript.Arguments.Count - 1
            strCodeToExec = "Set objExec" & intArgNum & " = wshShell.Exec(""cmd /c " & WScript.Arguments(intArgNum) & """)"
            Execute strCodeToExec
            If intArgNum < WScript.Arguments.Count - 1 Then
                  strWhileCondition = strWhileCondition & "objExec" & intArgNum & ".Status AND "
            Else
                  strWhileCondition = strWhileCondition & "objExec" & intArgNum & ".Status"
            End If
      Next
      strWhileCondition = strWhileCondition & VbCrLf & "WScript.Sleep 500" & VbCrLf & "Loop"
      'MsgBox strWhileCondition
      Execute strWhileCondition
End If
'===================

And you can use it in a batch file like this:

@echo off
start /wait RunAndWait.vbs file1.bat file2.bat file3.bat
start /wait RunAndWait.vbs file4.bat

Regards,

Rob.

Author

Commented:
Thank you kindly.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.