Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Write a batch file to execute a program after 5 sec and show the remaining time  (Read 4319 times)

0 Members and 1 Guest are viewing this topic.

whosyourdaddy

    Topic Starter


    Rookie
    How could I write a batch file to show the message like below and then run the program?
    10:00:00 aaa.txt is waiting 5 seconds to start up...
    10:00:01 aaa.txt is waiting 4 seconds to start up...
    10:00:02 aaa.txt is waiting 3 seconds to start up...
    10:00:03 aaa.txt is waiting 2 seconds to start up...
    10:00:04 aaa.txt is waiting 1 seconds to start up...

    Below is my script:

    @ECHO OFF
    setlocal
    set seconds=%5
    if "%seconds%"=="" set seconds=5
    ECHO %TIME% aaa.txt is waiting %seconds% seconds to start up...
    PING 127.0.0.1 -n %seconds% -w 1000  > NUL
    START /B C:\aaa.txt
    endlocal
    exit

    Dusty



      Egghead

    • I could if she would, but she won't so I don't.
    • Thanked: 75
    • Experience: Beginner
    • OS: Windows XP
    Try this script, the timing is not precise, you may want to do some work on that.

    Code: [Select]
    @echo off
    cls
    setlocal enabledelayedexpansion
       
    for /l %%1 in (5,-1,1) do (
        echo !time:~0,-3! aaa.txt is waiting %%1 second(s^) to startup...
        ping -n %%1 -w 100000 127.0.0.1 > nul
    )

    start /b "" c:\aaa.txt
    exit

    « Last Edit: June 18, 2009, 01:37:14 AM by Dusty »
    One good deed is worth more than a year of good intentions.

    whosyourdaddy

      Topic Starter


      Rookie
      Finally, I get a solution and want to share with all of you.

      Below is my new scripts:
      @echo off
      set sec=5

      :BEGIN
      if %sec%==0 GOTO END
      ECHO %TIME% aaa.txt is waiting %sec% seconds to start up...
      PING 127.0.0.1 -n 2 -w 1000  > NUL
      set /a sec -=1
      CLS
      goto BEGIN

      :END
      START /B C:\aaa.txt

      billrich

      • Guest
      C:\>type wait5.bat
      Code: [Select]
      @echo off


      ECHO %TIME% aaa.txt is waiting 5 seconds to start up...

      C:\batextra\sleep.exe 5
      ECHO %TIME%

      C:\aaa.txt

      Output:
      C:\>wait5.bat
       5:14:11.93 aaa.txt is waiting 5 seconds to start up...
       5:14:16.98