Jump to content

Pause in batch file


cuberob

Recommended Posts

Hi,

I have a small question, im wondering if i can in stead of using the /wait command use some pause for xxx seconds command because the /wait command aint working (it keeps on waiting... :P ).

example (that doesnt work)

ECHO.
ECHO Installing app.exe
start /wait %systemdrive%\app.exe
ECHO yes a popup appeared i'll close it
TASKKILL /F /IM app.exe

This doesnt work because because of the /wait command it never goes to the next step

example how i want is (with xxx i just give it more than enough time to finish installing)

ECHO.
ECHO Installing app.exe
start "/wait for xxx seconds" %systemdrive%\app.exe
ECHO yes a popup appeared i'll close it
TASKKILL /F /IM app.exe

so in this case the taskkill will kill the popup and it goes on installing.

Hope it exists! as for now ill keep on googling, (wasnt able to find anything yet)...

Link to comment
Share on other sites


As you might know there is no such command in batch files, the equivalent of UNIX "sleep" but there are two solutions:

1) use an external app:

DOS/Win9x/ME

http://short.stop.home.att.net/freesoft/batch2.htm

NT/2k/XP

Doze v1.0

http://sac-ftp.externet.hu/utiltask3.html

(+many more)

2) use a workaround:

(please note that it is different if the environment is DOS/Windows 9x/ME or NT/2k/XP)

http://www.robvanderwoude.com/wait.html

jaclaz

Link to comment
Share on other sites

Look for SLEEP.EXE...it'll do what you want. I think there's a copy in one of the Resource Kits.

ECHO.
ECHO Installing app.exe
%systemdrive%\app.exe
SLEEP xx
ECHO yes a popup appeared i'll close it
TASKKILL /F /IM app.exe

Just be sure to either include SLEEP.EXE in the same directory as your BAT/CMD or copy it to %SYSTEMROOT%.

Edited by nmX.Memnoch
Link to comment
Share on other sites

The following example works fine for me using the just the ping command without any 3rd party tools

@ECHO OFF
ECHO/
ECHO/ Running notepad.exe minimized for five seconds
START "" /MIN NOTEPAD.EXE &&(
ECHO/ YES the application started so i'll close it
PING -n 6 127.0.0.1>NUL &&(
TASKKILL /F /IM NOTEPAD.EXE >NUL
)
)

Link to comment
Share on other sites

For 10 secs delay use

PING 1.1.1.1 -n 1 -w 10000 >NUL

-----------------------------------------------------------------------------------------------------------------------------

For 60 secs delay use

PING 1.1.1.1 -n 1 -w 60000 >NUL

Regards.

Link to comment
Share on other sites

Or you can use VBS script

This has a message box that is counting down, the taskkill is hidden so there is no Cmd Window
Const Hide = 0, Norm = 1, Min = 2, Max =3 :  Dim Act, Cmd1, Cmd2, CT : CT = 6
Set Act = CreateObject("Wscript.Shell") '''' OBJECT FOR THE SCRIPT
Cmd1 = "Notepad.exe"
Cmd2 = "%Comspec% /c Taskkill.exe /F /IM Notepad.exe"
Act.Run(Cmd1),Min,False

Do
CT = CT - 1
Act.Popup CT ,1,"Count Down", 0 + 48
Loop Until CT = 0
Act.Run(Cmd2),Hide,True

This Sleeps for 6 seconds and no message box popup, taskkill is hidden
Const Hide = 0, Norm = 1, Min = 2, Max =3 :  Dim Act, Cmd1, Cmd2, CT : CT = 6
Set Act = CreateObject("Wscript.Shell") '''' OBJECT FOR THE SCRIPT
Cmd1 = "Notepad.exe"
Cmd2 = "%Comspec% /c Taskkill.exe /F /IM Notepad.exe"
Act.Run(Cmd1),Min,False : WScript.Sleep 6000 : Act.Run(Cmd2),Hide,True

Link to comment
Share on other sites

Going back to my original reply, and sticking with a literal pause, where you need to press a key to close the application, the following should work as expected

@ECHO OFF
ECHO/
ECHO/ Running notepad.exe minimized with a pause
START "" /MIN NOTEPAD.EXE &&(
ECHO/
ECHO/ The application started you may now close it
ECHO/
ECHO/ Press any key to close the application
PAUSE>NUL &&(
TASKKILL /F /IM NOTEPAD.EXE >NUL
)
)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...