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-08-05 02:05
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to implement executing a batch file in a loop with a 30-second interval?? View 2,953 Replies 8
Original Poster Posted 2006-08-02 15:23 ·  中国 江苏 苏州 移动
新手上路
Credits 8
Posts 2
Joined 2006-08-02 15:11
20-year member
UID 59682
Status Offline
Want to make an automatic batch file that executes cyclically every 30 seconds. How to achieve it? Originally, if I want to use the FOR loop method, which command should I call??? I've been thinking about it for a whole morning, really can't figure it out. Thanks!

[ Last edited by horser on 2006-8-2 at 15:27 ]
Floor 2 Posted 2006-08-02 15:38 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The following code has not set the statement to terminate the loop, please set it yourself.

@echo off
:loop
do something
ping 127.1 -n 30 >nul 2>nul
goto loop
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-08-02 15:56 ·  中国 江苏 苏州 移动
新手上路
Credits 8
Posts 2
Joined 2006-08-02 15:11
20-year member
UID 59682
Status Offline
Thanks! But I don't quite understand what " >nul 2>nul" means?
Floor 4 Posted 2006-08-02 21:09 ·  中国 辽宁 大连 教育网
中级用户
★★
DOS之友
Credits 332
Posts 168
Joined 2005-10-06 00:00
20-year member
UID 43171
Gender Male
From 天涯
Status Offline
hh.exe ntcmds.chm::/redirection.htm
Start Run. Just take a look at the above page to clear it up
测试环境: windows xp pro sp2 高手是这样炼成的:C:\WINDOWS\Help\ntcmds.chm
Floor 5 Posted 2006-08-02 23:36 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Re horser:

>nul 2>nul means that regardless of whether the execution of this statement is successful or not, the display of the execution result on the screen is blocked. For more content, please use the search function of the forum. In fact, this topic has been involved in many posts, and making good use of the search function of the forum will make you quickly become a batch processing expert.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-08-03 13:53 ·  中国 上海 徐汇区 电信
中级用户
★★
论坛第一菜鸟
Credits 361
Posts 166
Joined 2006-04-15 13:23
20-year member
UID 53870
Status Offline
nul is an empty device name, like a black hole.

> means to overwrite the output.

1 is the output stream, 2 is the error stream (1 can be omitted without writing).

>nul 2>nul means to not output the output information and error information of the command execution to the screen, but to an equipment that does not exist at all.

Common device names:
con console (keyboard and display)
aux, com1 - com4 all serial ports
prn, lpt1 - lpt3 all parallel ports
nul empty device
clock$ electronic clock
Can be referenced when writing commands, and files cannot be named with these names.

Redirection operators
> Write the command output to a file or device instead of writing it in the command prompt window.
< Read command input from a file instead of from the keyboard.
>> Add the command output to the end of the file without deleting the information in the file.
>& Write the output of one handle to the input of another handle.
<& Read input from one handle and write it to the output of another handle.
| Read output from one command and write it to the input of another command. Also called a pipeline.

0 input
1 output
2 error output
3-9 are individually defined by applications and various specific tools.
Diskette Operating System
Floor 7 Posted 2006-08-07 22:53 ·  中国 山东 淄博 联通
新手上路
Credits 2
Posts 1
Joined 2006-08-07 21:58
19-year member
UID 60062
Status Offline
The guidance from xjmxjm1234 has made me fully understand the symbols that I didn't understand before. Thank you very much
Floor 8 Posted 2007-06-18 14:55 ·  中国 江西 南昌 电信
初级用户
★★
Credits 193
Posts 98
Joined 2007-01-17 11:56
19-year member
UID 76803
Gender Male
Status Offline
A good post must be topped... The post by the LZ has made me understand a lot of things. The following work is thanks to the LZ

It automatically checks the process list every 20 seconds and automatically closes notepad.exe, which is the Notepad program. If needed, it can be changed to the name of a certain virus, which can play a monitoring role.

@echo off
:1
tasklist | find "notepad.exe" >>c:\notepad.luowei
if exist c:\notepad.luowei taskkill /f /im notepad.exe
ping 127.1 -n 20 >nul 2>nul
goto 1

[ Last edited by luowei14 on 2007-6-18 at 02:57 PM ]
这家伙很聪明 什么都没留下
Floor 9 Posted 2007-06-20 08:20 ·  IANA 局域网IP(Private-Use)
新手上路
Credits 16
Posts 8
Joined 2007-04-04 23:22
19-year member
UID 83972
Gender Male
Status Offline
Forum Jump: