China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-09 00:31
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please help the experts to modify this batch processing about time View 3,598 Replies 26
Original Poster Posted 2006-10-22 22:21 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
I'm now going to translate the content you provided. Please refer to the following:

The text you provided is in Chinese, and here is the translation:

I now need a batch processing. Starting from the current time, run a command after a specified time. I found the following batch processing program on the Internet, but it has a problem that it can't run correctly when the time is 0*:** because 0*+1 can't be added up. For example, when it's 08:30 in the morning, it can't run correctly, but it works after 10 o'clock because then adding 1 can be done, that is, the problem of the first number in the hour position being 0. How to solve this problem? Please help the experts modify the following batch processing so that it can be used within 24 hours a day, or provide other batch processing programs that meet my requirements. Thank you.

@echo off

setlocal ENABLEDELAYEDEXPANSION

set /a next_hour=0
set /a next_minute=0

for /F "tokens=1,2 delims=:" %%i in ('TIME /t') do (
rem Here 1 is the interval time, which can be adjusted according to your needs
set /a next_minute=%%j+1

set /a next_hour=%%i+1

if !next_minute! GEQ 60 (
set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
)

at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Floor 2 Posted 2006-10-23 00:48 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If there are leading zeros in the hours and minutes, the following code

set /a next_minute=%%j+1
set /a next_hour=%%i+1
can be modified to

set /a next_minute=1%%j-100+1
set /a next_hour=1%%i-100+1

Strangely, there is no case where the leading digit of the hour is zero on my machine.

[ Last edited by namejm on 2006-10-23 at 00:52 ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-10-23 00:55 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, which can be adjusted by yourself as needed
set a=%time:~0,2%
if %a:~0,1%==0 (set/a next_hour=%a:~1%+1) else set/a next_hour=a+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+1
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\Common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Floor 4 Posted 2006-10-23 01:23 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
The moderator is really smart. It works now. Thank you. (When using time, the leading zero won't appear for the hour, but when using time /t, it will. Moderator, you can try it.)
Floor 5 Posted 2006-10-23 01:38 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
Moderator, please modify it again. It's okay to set the time after 10 o'clock, but it's still not working if set before 10 o'clock, and it shows: There should not be <set/a. at this time.

[ Last edited by tianzizhi on 2006-10-23 at 01:43 ]
Floor 6 Posted 2006-10-23 02:43 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, which can be adjusted as needed
set/a next_hour=%time:~0,2%+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+1
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal

[ Last edited by qwe1234567 on 2006-10-23 at 04:22 ]
Floor 7 Posted 2006-10-23 02:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
——————————————————Moderation Record——————————————————
Executor: qwe1234567
Description: Duplicate topic posted {Please help me modify this batch processing about time} in {DOS Troubleshooting & Problem Discussion (Help Desk)}. Please do not post duplicate topics.
Action: Merge the topics and delete the original poster's duplicate topic post
————————————————————————————————————————
Floor 8 Posted 2006-10-23 03:59 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
The moderator missed a sentence, set a=%time:~0,2%
Thank you very much for letting me learn a lot of knowledge.

@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it according to your needs
set a=%time:~0,2%
set/a next_hour=a+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+50
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal

Now I've got it, after struggling for a long time, let me learn two different methods. One is a brain teaser, and the other is a rigorous DOS learning process. It's very good. It also let me learn the use of set offset and length.
Still, it's faster to learn things in application, hehe. It is suggested that friends learning DOS should learn in practice, and ask more questions for themselves.
Floor 9 Posted 2006-10-23 04:26 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Let's optimize it a bit. Here's the modified code:

@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it as needed
set /a next_hour=%time:~0,2% + 1
set /a next_minute=1%time:~3,2% - 100 + 1
if %next_minute% GEQ 60 (
set /a next_minute=!next_minute! - 60
set /a next_hour=!next_hour! + 1
if !next_hour! GEQ 24 set /a next_hour=!next_hour! - 24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
ooaf +2 2007-12-31 16:16
Floor 10 Posted 2006-10-23 04:43 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
Combine the two into one, good! I'll take both.
Floor 11 Posted 2006-10-23 04:52 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
Let me ask the moderator again. That GEQ is the meaning of greater than, then what is the one for less than? Why haven't I seen them before? In batch processing, the > < can't be used for comparison, right? Where can I find these similar symbols?
Floor 12 Posted 2006-10-23 05:50 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

EQU - equals
NEQ - not equals
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to

The reason why symbols like < and > cannot be used to judge size is that in batch processing, <, >, >> are all redirection symbols and have special uses.
Floor 13 Posted 2006-10-24 05:25 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
In the line `at !next_hour!:!next_minute! d:\常用\d.vbs`, `!next_hour!` and `!next_minute!` are also variables. The exclamation marks here are different from `%` in terms of usage in the context of batch scripting. In some cases, `!var!` is used for delayed expansion in batch when enabled with `setlocal enabledelayedexpansion`, while `%var%` is the normal expansion. But in this specific context related to the `at` command usage here, the main point is that they are variable placeholders with different delimiters from `%`.
Floor 14 Posted 2006-10-28 08:02 ·  中国 广西 柳州 电信
初级用户
Credits 25
Posts 14
Joined 2006-10-28 06:32
19-year member
UID 68613
Gender Male
Status Offline
Originally posted by qwe1234567 at 2006-10-23 04:26 AM:
Optimize it for you again
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it according to your needs
set/a next_hour=%time:~0,2%+1
set/a next_minute=1%time:~3,2%-100+1
if ...



May I ask the moderator, what does this interval of 1 represent? Is it 1 minute or 1 hour?
If I want to run the specified file after 20 minutes, how should I modify it? If it is 4 hours, how should I modify it?
Also, does this batch processing need to be run again after running once? It will run the specified file by itself when the specified time comes, right? Is it in the process all 24 hours?
at !next_hour!:!next_minute! d:\common\d.vbs
This refers to running the specified file.
Then this schtasks /delete /tn "zhang" /f
Does it mean to specify deleting the file named zhang under the F drive?
Please tell this newbie. I'm also learning. If this batch processing is really that magical, it's very important to me. Thank you.
Floor 15 Posted 2006-10-28 09:04 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Forum Jump: