Solved Batch file Pause command help

August 17, 2015 at 06:51:50
Specs: Windows XP
Hi guys,

Hope someone can point me in the right direction here.

I have created a script that closes explorer.exe > runs a specific program > once the program closes the script restarts explorer.exe. I have this running fine using the below script but I currently have a pause near the end which required user input which I want to automate without a user have to press a key, is there a way of doing this? if I remove the pause or use the choice or timeout option the script does not work as should. I could do with having the pause in but timing itself out after 3 seconds or so if at all possible.

taskkill /f /IM explorer.exe
start cmd.exe /c "c:\dir\dir\example.bat"
start explorer.exe

Thanks in advance.

See More: Batch file Pause command help

Report •

August 17, 2015 at 07:53:27
Replace the pause command with:
timeout /t 3

I think this does what you're looking for

However it skips if the user presses a key (as in, doesn't count fully 3), to prevent this use:

timeout /nobreak /t 3

Windows XP does not support the timeout command, instead you can use:

ping -n 1 -w 3000

where 3000 is three seconds. You can use "> nul" without the quotes to hide the output. Same goes for the timeout command.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ

Report •

August 17, 2015 at 08:07:19
Cheers RainBawZ but no joy im afraid.

Because I am calling a new cmd session to run my program which I have to do because of the way the program runs the original cmd session I have run the script in continues to run when my program is still opening to suns through the timeout and restarts explorer.exe before my program has actually started defeating the object a bit.

It works perfectly with the pause involved as when my program closes it closes its called cmd session and reverts back to my original script showing the pause to press any key to continue which I need to try and automate.


Report •

August 17, 2015 at 08:19:17
✔ Best Answer
Try removing the pause/timeout and instead use start with the /wait option:
start /wait cmd.exe /c "c:\dir\dir\example.bat"

This waits until the program has closed before proceeding.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

Report •

Related Solutions

August 17, 2015 at 10:07:01
taskkill /f /IM explorer.exe
call "c:\dir\dir\example.bat"
start explorer.exe

How To Ask Questions The Smart Way

Report •

August 18, 2015 at 01:13:10
Thanks for the replies guys.

RainBawZ solution worked a treat using the start /wait command.


Report •

Ask Question