How to wait for termination of program started with WshShell.Exec 
Author Message
 How to wait for termination of program started with WshShell.Exec

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

Thanks in advance



Thu, 13 Oct 2005 23:20:59 GMT  
 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



Fri, 14 Oct 2005 03:47:14 GMT  
 How to wait for termination of program started with WshShell.Exec
Thanks Michael, I'll try that

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



Fri, 14 Oct 2005 04:23:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. WshShell.Exec: reaping return codes and waiting for termination

2. WshShell.Run vs WshShell.Exec

3. runas with WshShell.Exec versus WshShell.Run

4. Problem using WshShell.Exec

5. how can i start a dos program and let the vb-program wait for it's termination?

6. Waiting for process termination in Scriptimh Host

7. Program Flow - wait for one sub to finish before starting another

8. Wait for program to start

9. How to start program and wait until it is complete from VB 4.0

10. Add'l: How to start program and wait until it is complete from VB 4.0

11. Shell, SendKeys, wait for program to start

12. using WshShell.Exec

 

 
Powered by phpBB® Forum Software