views:

97

answers:

4

Hi,

I want to open IE from a batch file and wait untill it is closed before going to the next line of the batch file. How to do this? BTW iexplore command seems to be not working in Windows 7 command line. Any idea why?

Thanks...

+1  A: 
start /wait whatever.exe

The /wait flag will make start wait until the program closes before it returns.

As for iexplore not working, you're right. That's curious... However, you can still invoke it with a full path:

start "" /wait "c:\Program Files\Internet Explorer\iexplore.exe" http://stackoverflow.com

I've updated the second command line to work around some manner of bug in start's command processing. It's weird. However, the proper way to do this is:

start /wait http://address.com
Mike Caron
/wait works for programs like notepad but fails for IE. Also if I include only the path to IE, then it opens a new command line instead of the browser. If I only give the link, it opens a new browser but still does not wait. If I try the command u have given exactly, still it does not wait untill I close the browser.
Manoj
start is stupid! When using quoted paths, you have to include a empty set of quotes first (for the title) Ex: start "" /wait "c:\random app.exe" (And you should also replace c:\Program Files with %programfiles%)
Anders
@Manoj It depends. I tested it, it works fine for IE. Just, as others have mentioned, the lifetime of the browser is funky, since you might just launch a tab in another process.
Mike Caron
@Anders Why is start stupid? And, why would you include empty quotes? That's kind of stupid, IMO. I tested my solution, and it works just fine. Note that /wait is a parameter to start, not to iexplore. Also, your answer seems to use start as well...
Mike Caron
For me also it works only when an empty quotes is placed before. I use IE 8 and Windows 7.
Manoj
Huh. That's really bizzare. NOW, it's also not working without the quotes. I swear it worked fine earlier!
Mike Caron
@Mike Caron: When the path/program string is in double quotes, you must provide the empty double quotes first, that's why I called start stupid (It was not like that on Win9x IIRC)
Anders
A: 

call "[path to ie executable]" webpage_address

peril brain
This does not seem to be waiting untill I close the browser.
Manoj
+2  A: 

Browsers are complicated when it comes to process lifetime, even back in the days before tabs, IE could have more than one window open in a single process. They also often use DDE to open urls making it hard to track the "correct" process. If you want to force the user to use IE (Why not use the default browser?) you could use windows scripting host to automate IE (Automation has some problems when it comes to protected IE IIRC)

I would recommend just a simple pause:

start /wait http://example.com
echo. When you are done reading xyz, press [Enter] to continue...
pause >nul
Anders
Note that this will cause the message to be delayed until the browser quits. This could potentially be forever, if the user opens other tabs, etc.
Mike Caron
Yes, that is true, if that is a problem, just remove /wait
Anders
A: 
call "C:\Program Files\Internet Explorer\iexplore.exe" www.google.com
call "C:\Program Files\Internet Explorer\iexplore.exe" www.stackoverflow.com
call "C:\Program Files\Internet Explorer\iexplore.exe" www.codeproject.com
echo done
pause

I tried it on windows 7 and it works perfectly....

test the code before posting ur comments.......