批量传递带有特殊字符的参数

时间:2019-08-21 08:58:38

标签: batch-file

我有一个脚本文件,可以通过这种方式接收一些参数:

echo --debug will run the tests but not run the installer. This need to be the first parameter.
echo --testcases=TESTCASES Provide a list of testcases to execute instead of those in App.config. The TESTCASES list commma-separated.
echo --dbkeys=DATABASEKEYS Provide a list of UTDB keys to prepare instead of those in App.config. The DB keys in question must be a subset of those mentioned in App.config. The DATABASEKEYS list should be commma-separated.

例如,您可以调用此文件 ./file.bat --testcases="test1, test2" --dbkeys="db1" 这部分工作正常,因为在脚本中我有这个调用:  call Test\MidTierLibUT\bin\Release\FleetManagerAPI.MidTierLibUT.exe %* || exit /b -2 但是如果我将第一个参数--debug放进去,我想在调用之前做其他事情 call Test\MidTierLibUT\bin\Release\FleetManagerAPI.MidTierLibUT.exe %* || exit /b -5,在%*中,我不希望--debug传递。

所以我尝试了:

shift
:start
if [%1] == [] goto done
set args=%args% %~1
shift
goto start

:done
call Test\MidTierLibUT\bin\Debug\FleetManagerAPI.MidTierLibUT.exe %args% || exit /b -5

但是%args%看起来像:--testcases test1 test2(不带“或=)

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

我想开箱即用,试图找到解决方案,并结合@aschipfl和@SomethingDark的想法,我认为将字符串的那部分全部删除并发送其余部分比较容易:) 所以解决方案是这样的:

set args=%*
set args= %args:--debug=%
Test\MidTierLibUT\bin\Debug\FleetManagerAPI.MidTierLibUT.exe %args% || exit /b -5

感谢您的帮助!

相关问题