I am creating a batch file to run a program on my desktop xyz.exe
for 4 hours, then close it for 1 hour and repeat the process. Here is my script.
:a
START C:\Users\Mukul\Desktop\xyz.exe
SLEEP 14400
taskkill /F /IM xyz.exe
SLEEP 3600
goto :a
According to here, the script should wait. It also says:
SLEEP 10
will delay execution of the next command by 10 seconds. so SLEEP 14400
should delay the execution by 4 hours.
Current results: Next command gets executed as soon as the first command completed.
Desired results: Next command should wait for 4 hours before executing the last command.
Delay execution for a few seconds or minutes, for use within a batch file. Syntax TIMEOUT delay [/nobreak] Key delay Delay in seconds (between -1 and 100000) to wait before continuing. The value -1 causes the computer to wait indefinitely for a keystroke (like the PAUSE command) /nobreak Ignore user key strokes.
The “sleep” command is used to add delay in some processes but unfortunately sleep or delay commands do not support windows operating systems. In the Windows operating system, we can utilize the “timeout” command that can delay the execution of commands for some seconds or for a specified time.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
To set your PC so it goes to sleep when you close the lid or press the power button: Open power options—select Start , then select Settings > System > Power & sleep > Additional power settings.
You can also use timeout
.
Here is an example:
@echo off
echo Hi
timeout /t 1 /nobreak > nul
/t
is not mandatory
1 is the amount of second(s) to wait
/nobreak
ensures the user can't skip the wait
> nul
redirects output to nothing, so you don't see anything
SLEEP command may not be supported by your Windows version. Try this:
:a
START C:\Users\Mukul\Desktop\xyz.exe
TIMEOUT 14400
taskkill /F /IM xyz.exe
TIMEOUT 3600
goto :a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With