Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with wsh.shell not waiting for command to finish executing 3

Status
Not open for further replies.

billieT

MIS
Dec 11, 2001
107
NZ
I'm trying to write a wee script to install Exchange + patches all at once. This is what I have so far:

Code:
Option Explicit
Dim FSO, WshShell, result
Set FSO = CreateObject("Scripting.FileSystemObject") 
Set WshShell = WScript.CreateObject("WScript.Shell")
result = WshShell.Run("Exchange2003\SETUP\I386\SETUP.EXE /unattendfile unattend.ini", 1, TRUE)
if result=0 then result = WshShell.Run("WindowsServer2003-KB831464-x86-ENU.exe /quiet /norestart", 1, TRUE)
...[serveral more patches]
if result=0 then wscript.echo ("Done!" & vbcrlf & vbcrlf & "Please REBOOT now.")

For some reason, instead of waiting for each line to finish executing, the script immediately starts processing the next line. The reason I chose vb was to avoid having to do the whole "command /c start /w" routine in DOS. If I have to do that here as well, I might as well do it in DOS.

If I'm doing something obviously stupid, please let me know.
 
Take a look at Woolsdog's post in this thread:

thread329-1038494

I hope you find this post helpful.

Regards,

Mark
 
All that Woolsdog suggests is using a variable instead of the TRUE value for bWaitOnReturn.

Since I'm explicitly setting it as TRUE, I don't see how using a variable is going to be any help whatsoever. Maybe I'll try removing the spaces.
 
billieT,

It depends very much on the implementation of setup.exe or any other application at that position.

Let's say setup.exe itself run as process A. Process A does some nominal verification then spawns a process B, the real installation engine, then close itself out. In this case, the bWaitOnReturn has done its work and the control will hand to the next statement. However, the process B is still running. That is out of the control of the bWaitOnReturn.

regards - tsuji
 
Bummer, that would most certainly be the case with the Exchange setup. And it also explains why the parts where I'm actually doing FSO stuff or running an commmand-line exe (which is echoing back to screen) are working as expected.

Thanks very much for the pointer, tsuji.
 
Hi,

use WshShell.Exec instead of WshShell.Run and wait until the process has finished.

Code:
'-----------------------------------------------------------------------
' execute commandline and get result into strResult
'-----------------------------------------------------------------------
Set oWsc = CreateObject("WScript.Shell")
Set oExec = oWsc.Exec(("Exchange2003\SETUP\I386\SETUP.EXE /unattendfile unattend.ini")
' wait until finished
Do While oExec.Status <> 1
	WScript.Sleep 100
Loop
'--------------------------------------------------------
' get output from StdOut and StdErr
'--------------------------------------------------------
strResult = oExec.StdOut.ReadAll() & oExec.StdErr.ReadAll()
Set oExec = Nothing

 
Thanks, fstrahberger, I did consider throwing a "sleep" command in there as well, but I didn't think of doing a loop to keep checking. I'm not that familiar with wscript.exec either.

Thanks again for the pointer!
 
I do _not_ think that .exec improves as such the situation as observed using .run in this particular application and in the general aspect. Just to clarify for other readers.
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top