我正在创build一个batch file,接受一个参数后跟一个文件名列表。 我想将文件名列表传递给batch file中的另一个可执行文件,但我不想也传递第一个参数。
喜欢这个:
Usage: LaunchTest.bat <config file> files ...
在哪里LaunchTest.bat是这样的:
SET CFGFILE=%1 @REM The below does not work, because %* still has the CFGFILE value of %1 in it @REM I thought I could 'shift', which moves %2, etc., down to %1, etc., but it @REM does not change the values in %*. @REM Testing.exe expects only the list of files. Testing.exe %*
任何想法如何从%*中删除一个参数,或构build一个任意长度的参数列表传递给一个命令?
谢谢,新年快乐。
@echo off echo config file: %~1 setlocal enableDelayedExpansion set "rest_of_line=" for %%a in (%*) do ( if !.!==. ( set "rest_of_line=!rest_of_line! %%a" ) set .=. ) endlocal && ( set "rest_of_line=%rest_of_line%" ) echo %rest_of_line%
@ECHO OFF SETLOCAL SET "parms=%*" CALL SET "parms=%%parms:*%1=%%" ECHO(%parms:~1% echo======= Second way SETLOCAL enabledelayedexpansion SET "parms=%*" SET "parms=!parms:*%1=!" ECHO(%parms:~1% GOTO :EOF
两种方式 – 有和没有delayedexpansion
。