tags:

views:

85

answers:

2

I created a .bat file with the below lines

cd C:\MyFolder
d:
findstr "Apple" C:\log.txt |findstr "red" > red_apples.txt
SLEEP 3600
GOTO START

When the bat is executed, the SLEEP is not working and the commands are running continously.

Is there anything wrong with the code? Please help !

+2  A: 

I don't believe Windows has a sleep, you can emulate it with ping, as shown in this example chkwait.cmd script:

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    echo %time%
    call :waitfor 20
    echo %time%
    endlocal
    goto :eof

:waitfor
    setlocal
    set /a "t = %1 + 1"
    >nul ping 127.0.0.1 -n %t%
    endlocal
    goto :eof

The call :waitfor 20 in the above script will wait for twenty seconds:

pax> chkwait
10:18:13.42
10:18:33.51
paxdiablo
Thank you paxdiablo. It worked.
A: 

SLEEP does not exist in windows batch script. You would have create your own Sleep wrapper EXE and call that from the batch. Or use the clever trick from @paxdiablo above.

Chris O
Thank you, Chris. paxdiablo's idea worked.