• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1324
  • Last Modified:

A method to cue multiple script sequential execution.

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
0
mgjust
Asked:
mgjust
4 Solutions
 
MrNevajCommented:
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.
0
 
Robberbaron (robr)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.



0
 
mish33Commented:
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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
RobSampsonCommented:
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.
0
 
RobSampsonCommented:
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.
0
 
mgjustAuthor Commented:
Thank you kindly.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now