WScript.Shell and blocking execution?

FlySwat picture FlySwat · Sep 8, 2008 · Viewed 12.9k times · Source

I'm using WScript to automate some tasks, by using WScript.Shell to call external programs.

However, right now it does not wait for the external program to finish, and instead moves on. This causes issues because I have some tasks dependent on others finishing first.

I am using code like:

ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir

Set wshShell = WScript.CreateObject("Wscript.Shell")
wshShell.run ZipCommand

Is there a way to do this so it blocks until the shell executed program returns?

Answer

FlySwat picture FlySwat · Sep 8, 2008

Turns out, that while loop is severe CPU hog :P

I found a better way:

ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir

Set wshShell = WScript.CreateObject("Wscript.Shell")

wshShell.Run ZipCommand,1,1

The last two arguments are Show window and Block Execution :)