Windows批处理文件多次运行jar文件

Vng*_*nge 5 java for-loop jar batch-file

我想制作一个从用户输入运行jar X次的批处理文件.我已经找了如何处理用户输入,但我不完全确定.在这个循环中,我想增加我发送给jar的参数.

截至目前,我不知道

  • 操纵for循环中的变量numParam,strParam

因此,当我从命令行运行这个小蝙蝠文件时,我能够进行用户输入,但是一旦进入for循环,就会吐出"命令的语法不正确

到目前为止,我有以下内容

@echo off

echo Welcome, this will run Lab1.jar
echo Please enter how many times to run the program
:: Set the amount of times to run from user input
set /P numToRun = prompt


set numParam = 10000
set strParam = 10000
:: Start looping here while increasing the jar pars
:: Loop from 0 to numToRun
for /L %%i in (1 1 %numToRun%) do (
    java -jar Lab1.jar %numParam% %strParam%

)
pause
@echo on
Run Code Online (Sandbox Code Playgroud)

任何建议都会有所帮助

编辑: 随着最近的更改,它似乎没有运行我的jar文件.或者至少似乎没有运行我的测试回声程序.似乎我的用户输入变量没有设置为我输入的值,它保持为0

Vng*_*nge 1

我上一期所发生的事情是变量如何扩展的。这实际上是 dreamincode.net 的答案:Here

最终代码:

@echo off

echo Welcome, this will run Lab1.jar
:: Set the amount of times to run from user input
set /P numToRun= Please enter how many times to run the program: 

set /a numParam = 1000
set /a strParam = 1000

setlocal enabledelayedexpansion enableextensions


:: Start looping here while increasing the jar pars
:: Loop from 0 to numToRun
for /L %%i in (1 1 %numToRun%) do (
    set /a numParam = !numParam! * 2
    set /a strParam = !strParam! * 2
    java -jar Lab1.jar !numParam! !strParam!

    :: The two lines below are used for testing
    echo %numParam%  !numParam!
    echo %strParam%  !strParam!
)

@echo on
Run Code Online (Sandbox Code Playgroud)