
How to wait for termination of program started with WshShell.Exec
Quote:
> Dear All,
> How can I stop the prosessing of a server-side script (in an ASP
> file) to wait for the termination of a program started with
> WshShell.Exec.
> The program returns an exitcode that I have to respond to and the
> problem is that the objWshShell.Exec(strCmnd) does not wait until the
> termination and I don't get the correct ExitCode.
> I found some example code using Wscript.Sleep, but that doesn't work
> in a server-side script (I get an error indicating Wscript is not
> defined)
> The following dirty trick works, but I look for a 'cleaner' solution.
> strCmnd = "MyCommand.exe " & parameters
> Set objWshShell = CreateObject("WScript.Shell")
> Set objCmnd = objWshShell.Exec(strCmnd)
> ExitCounter = 0
> Do While objCmnd.Status = 0 and ExitCounter < 20000
> ExitCounter = ExitCounter + 1
> Loop
Take the script code that uses the WshShell.Exec method and put it in an
external *.vbs script in a folder on the server where the ASP code can
execute it under cscript.exe using the WshShell.Run method with the wait
option.
Since the code is now running under cscript, the wscript.sleep method is
available.
Your only other choice is a 3rd party component (or one you write yourself)
the provides the equivalent of WScript.Sleep to ASP code.
--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp