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
LVL 2
ccampbell15Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
Can you try this instead:

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

cmd explicitly starts a new 'shell' that runs your .cmd file
0
Bill PrewCommented:
How are you running the VBS script.  If you run it from a command line or batch file as:

cscript //nologo test.vbs

Then you will get the effect you want with your existing code.

If you run either from Windows Explorer, or a command line with WSCRIPT then it will not wait for the CMD script to complete.

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ccampbell15Author Commented:
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
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Gerwin Jansen, EE MVETopic Advisor Commented:
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?
0
Bill PrewCommented:
So are you testing the vbs script or are you testing the converted exe version of it?

What version of Windows?

~bp
0
ccampbell15Author Commented:
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
0
ccampbell15Author Commented:
Oh forgot,

Win7 Pro
0
Bill PrewCommented:
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
0
Bill PrewCommented:
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
0
ccampbell15Author Commented:
Oh Geez,

I had 2 folders with the same filenames.  Edit the file in one folder but running the other - DUH!
Sorry guys.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
No problem at all, glad you've found it ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.