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

Author Topic: How to delay execution or make the DOS batch file to SLEEP  (Read 1810 times)

0 Members and 1 Guest are viewing this topic.

Helen09122010

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    How to delay execution or make the DOS batch file to SLEEP
    « on: July 24, 2012, 12:08:57 AM »
    Hi All,

    I have a batch file that i need to execute every 60 sec until the counter value is equal to 100. Pause does not help me. Some one has to press any key. Instead i want the batch file to wake up every 60 sec, execute some commands, increment the counter then sleep for 60 sec ... until counter =100. How can i do this

    @ECHO OFF
    SET TIMER=1
    :FINISH
    DO some commands
    SET /a TIMER=TIMER+1

    IF %TIMER% LSS 100 GOTO FINISH
    IF %TIMER% GTR 100 GOTO EXIT

    :EXIT

     ???


    foxidrive



      Apprentice
    • Thanked: 73
    • Experience: Experienced
    • OS: Windows 7
    Re: How to delay execution or make the DOS batch file to SLEEP
    « Reply #2 on: July 24, 2012, 04:34:04 AM »
    You can use ping to delay for around 60 seconds, if that is what you want to do.

    Code: [Select]
    @ECHO OFF
    SET TIMER=1
    :FINISH
    DO some commands
    SET /a TIMER=TIMER+1
    ping -n 60 localhost >nul
    IF %TIMER% LSS 100 GOTO FINISH

    Helen09122010

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: How to delay execution or make the DOS batch file to SLEEP
      « Reply #3 on: July 24, 2012, 05:20:38 AM »
      Hey

      Thanks very much!!

      that works for me

      hehehe..
       :o

      Squashman



        Apprentice
      • Thanked: 44
        • Experience: Experienced
        • OS: Other
        Re: How to delay execution or make the DOS batch file to SLEEP
        « Reply #4 on: July 24, 2012, 05:45:14 AM »
        Also if you are on Vista or Windows 7 it has a dedicated command for this called TIMEOUT

        foxidrive



          Apprentice
        • Thanked: 73
        • Experience: Experienced
        • OS: Windows 7
        Re: How to delay execution or make the DOS batch file to SLEEP
        « Reply #5 on: July 24, 2012, 10:30:18 AM »
        Quote
        Also if you are on Vista or Windows 7 it has a dedicated command for this called TIMEOUT

        Thanks for that.  I sat here knowing there was a native command and tried SLEEP and WAIT which are perfectly good command names but they don't exist - I didn't recall it was TIMEOUT. :)

        Salmon Trout



          Sage

          Thanked: 647
          • Yes
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: How to delay execution or make the DOS batch file to SLEEP
        « Reply #6 on: July 24, 2012, 11:51:28 AM »
        Thanks for that.  I sat here knowing there was a native command and tried SLEEP and WAIT which are perfectly good command names but they don't exist - I didn't recall it was TIMEOUT. :)

        Sleep.exe is in the various Windows Resource Kits - the Windows Server 2003 Resource Kit ("Reskit") can be downloaded here

        http://www.microsoft.com/en-us/download/details.aspx?id=17657


        Proud to be European