windows 批处理文件每1分钟执行一次命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4313146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:48:07  来源:igfitidea点击:

batch file to execute a command in it every 1 minute

windowsbatch-filerepeat

提问by Pratik

i want to create a batch file that executes command in it every 1 minute.

我想创建一个批处理文件,每 1 分钟在其中执行一次命令。

how can i go ahead with this ?

我怎么能继续呢?

what i want to do is :

我想做的是:

download a file from somedomain.com/updates.html to a new file every 1 min. or so i don't have any .NET framework installed here, so i thought of going with batch files.

每 1 分钟从 somedomain.com/updates.html 下载一个文件到一个新文件。或者我这里没有安装任何 .NET 框架,所以我想使用批处理文件。

After googling a bit a got http://www.chami.com/tips/windows/062598W.html

谷歌搜索后得到了http://www.chami.com/tips/windows/062598W.html

now what i want is to call 1 command whic downloads & writes a new file every 1 minute.

现在我想要的是每 1 分钟调用 1 个命令下载并写入一个新文件。

采纳答案by T33C

From http://malektips.com/dos0017.html

来自http://malektips.com/dos0017.html

Do you need a batch file that waits a certain amount of seconds? In some languages, the command would be WAIT, but DOS and Windows do not come with this command for batch files. If you want to implement the WAIT command:

您是否需要等待特定秒数的批处理文件?在某些语言中,该命令为 WAIT,但 DOS 和 Windows 没有为批处理文件提供此命令。如果要实现 WAIT 命令:

For DOS, Windows 95, and Windows 98 machines

对于 DOS、Windows 95 和 Windows 98 机器

Create the following batch file and name it WAIT.BAT.

创建以下批处理文件并将其命名为 WAIT.BAT。

@CHOICE /T:N,%1% > NUL

@CHOICE /T:N,%1% > NUL

Now, in order to wait 10 seconds in a batch file, just call the WAIT.BAT batch file as follows:

现在,为了在批处理文件中等待 10 秒,只需按如下方式调用 WAIT.BAT 批处理文件:

CALL WAIT 10

呼叫等待 10

For Windows 95, Windows 98, Windows NT, Windows 2000, Windows XP, or Windows 2003 machines

对于 Windows 95、Windows 98、Windows NT、Windows 2000、Windows XP 或 Windows 2003 机器

You can use the following WAIT.BAT, as the CHOICE command is not included in the default install on Windows NT, Windows 2000, Windows XP, or Windows 2003:

您可以使用以下 WAIT.BAT,因为 CHOICE 命令不包括在 Windows NT、Windows 2000、Windows XP 或 Windows 2003 上的默认安装中:

@ping 127.0.0.1 -n 2 -w 1000 > nul @ping 127.0.0.1 -n %1% -w 1000> nul

@ping 127.0.0.1 -n 2 -w 1000 > nul @ping 127.0.0.1 -n %1% -w 1000> nul

The reason for the two lines is that in order to wait using the PING command, you must add extra pings to correctly wait the desired number of seconds. Also, since the PING command is being used, it is possible that this WAIT batch file may run over a few milliseconds. Thus, it is not recommended to use this for critical real-time processing.

出现这两行的原因是为了使用 PING 命令等待,您必须添加额外的 ping 以正确等待所需的秒数。此外,由于正在使用 PING 命令,因此此 WAIT 批处理文件可能会运行几毫秒。因此,不建议将其用于关键的实时处理。

Windows XP and Windows 2003 machines

Windows XP 和 Windows 2003 机器

Since Windows XP and 2003 users do not have the CHOICE command, if you find the PING alternative not to your liking, the Windows 2003 Resource Kit has a batch file SLEEP command.

由于 Windows XP 和 2003 用户没有 CHOICE 命令,如果您发现 PING 替代方案不符合您的喜好,Windows 2003 Resource Kit 有一个批处理文件 SLEEP 命令。

回答by Pratik

I recommend using Scheduled tasks in windows for this! Don't add the scheduling/loop in your batch file!

为此,我建议在 Windows 中使用计划任务!不要在批处理文件中添加调度/循环!

回答by denver

While there is no wait command available at a command prompt, this was a common problem and MS did release a sleep command as part of the resource kit. You can just use the sleep.exe command in a while loop.

虽然命令提示符下没有可用的等待命令,但这是一个常见问题,MS 确实发布了睡眠命令作为资源工具包的一部分。您可以只在 while 循环中使用 sleep.exe 命令。

I got sleep.exe from the Windows 2003 Resource Kit which can be found online.

我从 Windows 2003 Resource Kit 中获得了 sleep.exe,它可以在线找到。