Batch file 如何使bat文件自身打开一定次数
我有一个bat文件,我必须快速单击以使其打开很多次,但我想使其打开,所以我只需单击一次,它就会打开50次。最简单的方法是通过命令行在Batch file 如何使bat文件自身打开一定次数,batch-file,Batch File,我有一个bat文件,我必须快速单击以使其打开很多次,但我想使其打开,所以我只需单击一次,它就会打开50次。最简单的方法是通过命令行在for/L循环中调用脚本 for /L %A in (1,1,50) do start "" cmd /c script.bat 您也可以使用相同的代码编写包装器脚本(尽管将%a更改为%a) 如果出于某种原因,这是不可接受的,您还可以跟踪脚本使用临时文件打开的次数 @echo off setlocal enabledelayedexpansion set SCR
for/L
循环中调用脚本
for /L %A in (1,1,50) do start "" cmd /c script.bat
您也可以使用相同的代码编写包装器脚本(尽管将%a
更改为%a
)
如果出于某种原因,这是不可接受的,您还可以跟踪脚本使用临时文件打开的次数
@echo off
setlocal enabledelayedexpansion
set SCRIPT_INSTANCES=50
:: Create a temporary file if one doesn't already exist
if not exist script_count.txt >script_count.txt echo(%SCRIPT_INSTANCES%
:: Read in the value of the config file
set /p script_counter=<script_count.txt
:: If the value of script_counter is greater than 1, decrement it and start again
if %script_counter% gtr 1 (
set /a script_counter-=1
>script_count.txt echo(!script_counter!
start "" cmd /c "%~0"
) else (
del script_count.txt
)
:: THE REST OF YOUR CODE GOES UNDER THIS LINE
@echo关闭
延迟扩展
设置脚本_实例=50
::如果临时文件不存在,请创建一个临时文件
如果不存在script\u count.txt>script\u count.txt回显(%script\u实例%
::读取配置文件的值
set/p script\u counter=script\u count.txt echo(!script\u counter!
启动“cmd/c”%~0
)否则(
del script_count.txt
)
::代码的其余部分在这一行下面
最简单的方法是通过命令行在for/L
循环中调用脚本
for /L %A in (1,1,50) do start "" cmd /c script.bat
您也可以使用相同的代码编写包装器脚本(尽管将%a
更改为%a
)
如果出于某种原因,这是不可接受的,您还可以跟踪脚本使用临时文件打开的次数
@echo off
setlocal enabledelayedexpansion
set SCRIPT_INSTANCES=50
:: Create a temporary file if one doesn't already exist
if not exist script_count.txt >script_count.txt echo(%SCRIPT_INSTANCES%
:: Read in the value of the config file
set /p script_counter=<script_count.txt
:: If the value of script_counter is greater than 1, decrement it and start again
if %script_counter% gtr 1 (
set /a script_counter-=1
>script_count.txt echo(!script_counter!
start "" cmd /c "%~0"
) else (
del script_count.txt
)
:: THE REST OF YOUR CODE GOES UNDER THIS LINE
@echo关闭
延迟扩展
设置脚本_实例=50
::如果临时文件不存在,请创建一个临时文件
如果不存在script\u count.txt>script\u count.txt回显(%script\u实例%
::读取配置文件的值
set/p script\u counter=script\u count.txt echo(!script\u counter!
启动“cmd/c”%~0
)否则(
del script_count.txt
)
::代码的其余部分在这一行下面
预期要运行的语法:
thisbatchname实例是必需的
例如,如果以参数3开始批处理,times
变为2,并且由for/L
由于额外实例没有参数,因此时间
将设置为-1
,因此不会创建额外实例
当然,用所需的批处理命令系列替换暂停
预期要运行的语法:
thisbatchname实例是必需的
例如,如果以参数3开始批处理,times
变为2,并且由for/L
由于额外实例没有参数,因此时间
将设置为-1
,因此不会创建额外实例
当然,用所需的批处理命令系列替换暂停