首页 > 解决方案 > CMD 仅使用多个参数之一启动 .exe

问题描述

我希望我的批处理脚本在没有我输入的情况下自行随机选择一个参数(从大约 70 个参数中,例如 param1 - param70)。

除了随机参数外,exe 还有更多参数始终保持不变。

我不知道如何将其放入代码中。

这是我的想法的一个例子:

param1=--abc
param2=--mno
param3=--xyz

./example.exe --hello --world --(param1 OR param2 OR param3)

等于:

./example.exe --hello --world --abc

或者

./example.exe --hello --world --mno

或者

./example.exe --hello --world --xyz

标签: powershellbatch-file

解决方案


这可以批量工作。不过,您需要设置每个参数。

set /a numb=%random% %% 3
goto :param%numb%

:param0
Set "var=abc"
Goto :execute

:param1
Set "var=mno"
Goto :execute

:param2
Set "var=xyz"
Goto :execute

:execute
.\example.exe --hello --%var%

对于 70 参数,您需要更改%% 3%% 70


推荐阅读