Link to home
Create AccountLog in
Avatar of ccampbell15
ccampbell15

asked on

WshShell.Run doesn't wait

Hi all,

I reduced things to a very simple test case because I just can't get WshShell.Run  to wait until the cmd file it calls to complete.

test.vbs
Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run ("C:\hello.cmd", 2,TRUE)


hello.cmd
echo hello
pause

I was expecting the test.vbs to open the cmd file minimized and remain open until I hit the enter key in the cmd window.

According to http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
that should work.

Can somone move one of the trees so I can see the forest please?

Regards
Lee
SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ccampbell15
ccampbell15

ASKER

I created yet another cmd file that calls the vbs like cscript //nologo test.vbs.  The vbs then calls the script I want to run but still does not wait.

The test.vbs is actually a larger script that is part of an installer package.  Using an app from Xneat I convert the .vbs to a .exe so I can run it and wait on that file to complete before moving on.

So far I can’t get the WaitOnReturn to actually wait.  


cmd /c  makes no difference.  The cms file is doing what it's supposed to the WaitOnReturn  inside of the vbs is not
What I'm suggesting (and tested) is that test.vbs contains:

Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run ("cmd /c C:\temp\hello.cmd", 2,TRUE)

and that hello.cmd contains:

echo hello
pause

If I run test.vbs from a cmd prompt (on c:\temp), I get a new cmd prompt that is displaying:

C:\Temp>echo hello
hello

C:\Temp>pause
Press any key to continue . . .

Did you try that / does it work for you?
So are you testing the vbs script or are you testing the converted exe version of it?

What version of Windows?

~bp
I'm tested both the exe and the vbs.  I created a .cmd that called the .vbs using cscript and also tried the .exe

The cmd file itself does indeed wait until I enter the enter key.  The problem is that the vbs does not wait.  It fied off the cmd and just went on it merry way
Oh forgot,

Win7 Pro
Well, this is quite strange. I am on 32 bit Win 7 Pro as well, and am doing exactly what you are doing, and the vbscript doesn't exit until after I press enter in the new command window.

~bp
Try changing your RUN to this, and see if it waits until you exit notepad or not (it does here).

return = WshShell.Run ("notepad", 2,TRUE)

~bp
Oh Geez,

I had 2 folders with the same filenames.  Edit the file in one folder but running the other - DUH!
Sorry guys.
No problem at all, glad you've found it ;)