问题描述
我要执行命令100-200倍,到目前为止,我的研究表明,我要么必须复制/粘贴此命令的100个拷贝,或使用为
循环,但 环路期望的项目清单,因此我需要200个文件进行操作,或200项列表,从而击败了点。
I need to execute a command 100-200 times, and so far my research indicates that I would either have to copy/paste 100 copies of this command, OR use a for
loop, but the for
loop expects a list of items, hence I would need 200 files to operate on, or a list of 200 items, hence defeating the point.
我宁可不要写一个C程序,并通过记录的长度,为什么我不得不写另一个程序来执行用于测试目的,我的计划。我的程序本身的修改也是不是一个选项。
I would rather not have to write a C program and go through the length of documenting why I had to write another program to execute my program for test purposes. Modification of my program itself is also not an option.
所以,对于一个命令,<一>,我将如何通过批处理脚本执行了N次
So, given a command, <a>, how would I execute it N times via a batch script?
推荐答案
为/ L
是您的朋友:
for /l %x in (1, 1, 100) do echo %x
由一个从1开始,步骤,并在100结束。
Starts at 1, steps by one, and finishes at 100.
使用两个%
■如果它在一个批处理文件
Use two %
s if it's in a batch file
for /l %%x in (1, 1, 100) do echo %%x
(这是我真的真的很讨厌有关Windows脚本的事情之一)
(which is one of the things I really really hate about windows scripting)
如果您有循环的每个迭代多个命令,这样做:
If you have multiple commands for each iteration of the loop, do this:
for /l %x in (1, 1, 100) do (
echo %x
copy %x.txt z:\whatever\etc
)
或批处理文件中的
or in a batch file
for /l %%x in (1, 1, 100) do (
echo %%x
copy %%x.txt z:\whatever\etc
)
这篇关于批处理脚本循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!