问题描述
我想从DOS窗口多次执行一个操作。常识告诉我一个DOS FOR循环应该能够处理这个。果然,如果我想要执行,比如说, myProg.exe
,我可以打开一个命令窗口并使用: C:\> (1 2 3)DO myProg.exe
简单。
但是如果我想执行 myProg.exe
1000次呢?我想在FOR循环中指定一个范围,但是我很难看到怎么做。
C:\> FOR%i in(1 to 1000)DO myProg.exe
C:\> FOR%i(1-1000)DO myProg.exe
但是,工作。 FOR循环分别将列表解释为3个标记和1个标记,因此 myProg.exe
只分别执行3次和1次。
批处理文件解决方案
编写某种批处理(.bat)文件:
pre $ SET $ COUNT = 0
MyLoop
IF%COUNT%==1000GOTO EndLoop
myProg.exe
SET / A COUNT + = 1
GOTO MyLoop
:EndLoop
$ b
但是有没有简单的方法从命令行执行此操作?
例如。
C:\> FOR / l%i in(1,1,1000)DO myProg.exe
这就是循环遍历范围,从1开始,每次步进1,直到1000
$ b
I want to perform an operation multiple times from a DOS window. Common sense tells me that a DOS FOR loop should be able to handle this. Sure enough, if I want to execute, say, myProg.exe
, I can open a command window and use:
C:\> FOR %i in (1 2 3) DO myProg.exe
Easy.
But what if I want to execute myProg.exe
1000 times? I want to specify a range in the FOR loop, but I'm having trouble seeing how to do this.
Intuitively, it seems like I should be able to do something like one of the following:
C:\> FOR %i in (1 to 1000) DO myProg.exe
C:\> FOR %i in (1-1000) DO myProg.exe
But, of course, this doesn't work. The FOR loop interprets the list as 3 tokens and 1 token, respectively, so myProg.exe
is only executed 3 times and 1 time, respectively.
Batch File Solution
It'd probably be easy to write some sort of batch (.bat) file:
SET COUNT=0
:MyLoop
IF "%COUNT%" == "1000" GOTO EndLoop
myProg.exe
SET /A COUNT+=1
GOTO MyLoop
:EndLoop
But isn't there an easy way to do this from the command line?
You can use the /l tag in your statement to make it loop through a set of numbers.
eg.
C:\> FOR /l %i in (1,1,1000) DO myProg.exe
This says loop through the range, starting at 1, stepping 1 at a time, until 1000
这篇关于DOS FOR循环通过命令行的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!