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

前端之家收集整理的这篇文章主要介绍了java – Windows批处理文件多次运行jar文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想制作一个从用户输入运行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

任何建议都会有所帮助

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

最佳答案
如果您阅读文档(从命令行输入或为/?键入帮助),您将看到执行FOR循环固定次数的正确语法.

for /L %%i in (1 1 %numToRun%) do java -jar Lab1.jar %numParam% %strParam%

如果要使用多行,则必须使用行继续

for /L %%i in (1 1 %numToRun%) do ^
  java -jar Lab1.jar %numParam% %strParam%

或括号

for /L %%i in (1 1 %numToRun%) do (
  java -jar Lab1.jar %numParam% %strParam%
  REM parentheses are more convenient for multiple commands within the loop
)
原文链接:https://www.f2er.com/java/438266.html

猜你在找的Java相关文章