Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WScript.Shell and blocking execution?

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?

like image 588
FlySwat Avatar asked Sep 08 '08 18:09

FlySwat


People also ask

What does WScript shell mean?

WshShell is a generic name for a powerful object that enables you to query and interact with various aspects of the Windows shell. You can display information to the user, run applications, create shortcuts, work with the Registry, and control Windows' environment variables.

What is WScript CreateObject?

The WScript CreateObject method interprets the second parameter as a subroutine prefix to be used in handling events from the object. The two GetObject functions are similarly related. (Adapted from TechNet, section "Comparing VBScript CreateObject and GetObject Functions with WSH".)


1 Answers

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

like image 73
FlySwat Avatar answered Sep 25 '22 03:09

FlySwat