<p>I'm using <a href="http://en.wikipedia.org/wiki/Windows_Script_Host#Usage" rel="noreferrer">WScript</a> to automate some tasks, by using WScript.Shell to call external programs.</p>

<p>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.</p>

<p>I am using code like:</p>

<pre><code>ZipCommand = "7za.exe a -r -y " &amp; ZipDest &amp; BuildLabel &amp; ".zip " &amp; buildSourceDir

Set wshShell = WScript.CreateObject("Wscript.Shell")
wshShell.run ZipCommand
</code></pre>

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

[{'answer_id': 50395, 'author': 'Guy Starbuck', 'author_id': 2194, 'author_profile': 'https://Stackoverflow.com/users/2194', 'pm_score': 3, 'selected': False, 'text': '<p>If you use the "Exec" method, it returns a reference, so you can poll the "Status" property to determine when it is complete.  Here is a sample from <a href="http://msdn.microsoft.com/en-us/library/ateytk4a(VS.85).aspx" rel="noreferrer">msdn</a>:</p>\n\n<pre><code>Dim WshShell, oExec\nSet WshShell = CreateObject("WScript.Shell")\n\nSet oExec = WshShell.Exec(ZipCommand)\n\nDo While oExec.Status = 0\n    WScript.Sleep 100\nLoop\n</code></pre>\n'}, {'answer_id': 50458, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 4, 'selected': False, 'text': '<p>Turns out, that while loop is severe CPU hog :P</p>\n\n<p>I found a better way:</p>\n\n<pre><code>ZipCommand = "7za.exe a -r -y " &amp; ZipDest &amp; BuildLabel &amp; ".zip " &amp; buildSourceDir\n\nSet wshShell = WScript.CreateObject("Wscript.Shell")\n\nwshShell.Run ZipCommand,1,1\n</code></pre>\n\n<p>The last two arguments are Show window and Block Execution :)</p>\n'}]
['https://Stackoverflow.com/questions/50384', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1965/']