Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
mohdfraz
- Posts: 69
- Joined: 29 Jun 2011 11:16
#1
Post
by mohdfraz » 26 May 2014 08:32
Hello,
I want to run a code in a specific time of the day. This below code looks fine. But there is a problem If I run this code in between 1900 and 1930 time. It will work fine. But if I start this code before 1900. It will not work. What is wrong with this code?
Thanks
Code: Select all
:loop
@echo off
set t=%time:~0,5%
set t=%t::=%
if %t% gtr 1900 (goto :checklss) else (goto :1end)
:Checklss
if %t% lss 1930 (goto :Start) else (goto :1end)
:Start
msg * Started.......
:1End
Ping -n 5 127.1.1.1
goto Loop
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 26 May 2014 09:10
Is this what you want to do?
Code: Select all
@echo off
:loop
set t=%time%
set t=%t:~0,2%%t:~3,2%
if %t% GEQ 1900 if %t% LEQ 1930 msg * Started....... & goto :EOF
Ping -n 5 127.1.1.1
goto Loop
-
mohdfraz
- Posts: 69
- Joined: 29 Jun 2011 11:16
#3
Post
by mohdfraz » 26 May 2014 11:14
foxidrive wrote:Is this what you want to do?
Code: Select all
@echo off
:loop
set t=%time%
set t=%t:~0,2%%t:~3,2%
if %t% GEQ 1900 if %t% LEQ 1930 msg * Started....... & goto :EOF
Ping -n 5 127.1.1.1
goto Loop
Thank you very much Foxidrive.
I changed
gtr to geq
and lss to leq
and this below code also started working. One think I don't understand why GTR did not worked?
Thanks
Code: Select all
:loop
@echo off
set t=%time:~0,5%
set t=%t::=%
if %t% geq 1935 (goto :checklss) else (goto :1end)
:Checklss
if %t% leq 1936 (goto :Start) else (goto :1end)
:Start
msg * Started.......
:1End
Ping -n 5 127.1.1.1
goto Loop
-
mohdfraz
- Posts: 69
- Joined: 29 Jun 2011 11:16
#5
Post
by mohdfraz » 26 May 2014 23:56
Squashman wrote:what is wrong with using a scheduled task?
a) I found it not reliable. It don't run. Although test runs works fine.
b) complex schedule task cannot be done by it. where different tasks run require different tasks feed back first.
c) It can start a process but it don't have a END time in it to stop that running process. For example loop processes.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 27 May 2014 06:27
Going to disagree with you on at least two of your points because I don't understand what you are referring to in one of them.
Windows Task Scheduler is 100% reliable! I have at least 60+ Windows Scheduled tasks that run either on a daily, weekly or monthly basis. Some of them have multiple schedules. These tasks have been running this way for YEARS! I do task Automation for a living! You can't BS me with that excuse.
You can certainly have an end time for your process. Have Task Scheduler stop the task after X amount of hours from when it starts.
-
mohdfraz
- Posts: 69
- Joined: 29 Jun 2011 11:16
#7
Post
by mohdfraz » 27 May 2014 06:36
Squashman wrote:Going to disagree with you on at least two of your points because I don't understand what you are referring to in one of them.
Windows Task Scheduler is 100% reliable! I have at least 60+ Windows Scheduled tasks that run either on a daily, weekly or monthly basis. Some of them have multiple schedules. These tasks have been running this way for YEARS! I do task Automation for a living! You can't BS me with that excuse.
You can certainly have an end time for your process. Have Task Scheduler stop the task after X amount of hours from when it starts.
Squashman,
Ok, I will re-check it. What is the way to run Error.bat if any of Tasks are not completed successfully?