中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-05 03:08
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to implement executing a batch file in a loop with a 30-second interval??
Printable Version  2,955 / 8
Floor1 horser Posted 2006-08-02 15:23
新手上路 Posts 2 Credits 8
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 ]
Floor2 namejm Posted 2006-08-02 15:38
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The following code has not set the statement to terminate the loop, please set it yourself.
Floor3 horser Posted 2006-08-02 15:56
新手上路 Posts 2 Credits 8
Thanks! But I don't quite understand what " >nul 2>nul" means?
Floor4 IceCrack Posted 2006-08-02 21:09
中级用户 Posts 168 Credits 332 From 天涯
hh.exe ntcmds.chm::/redirection.htm
Start Run. Just take a look at the above page to clear it up
Floor5 namejm Posted 2006-08-02 23:36
荣誉版主 Posts 1,737 Credits 5,226 From 成都
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.
Floor6 xjmxjm1234 Posted 2006-08-03 13:53
中级用户 Posts 166 Credits 361
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.
Floor7 studyit Posted 2006-08-07 22:53
新手上路 Posts 1 Credits 2
The guidance from xjmxjm1234 has made me fully understand the symbols that I didn't understand before. Thank you very much
Floor8 luowei14 Posted 2007-06-18 14:55
初级用户 Posts 98 Credits 193
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 ]
Floor9 jzcn Posted 2007-06-20 08:20
新手上路 Posts 8 Credits 16
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023