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.Shel l")
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
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.Shel
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I'm suggesting (and tested) is that test.vbs contains:
Set WshShell = CreateObject("WScript.Shel l")
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?
Set WshShell = CreateObject("WScript.Shel
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
What version of Windows?
~bp
ASKER
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
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
ASKER
Oh forgot,
Win7 Pro
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
~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
return = WshShell.Run ("notepad", 2,TRUE)
~bp
ASKER
Oh Geez,
I had 2 folders with the same filenames. Edit the file in one folder but running the other - DUH!
Sorry guys.
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 ;)
ASKER
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