我的批处理脚本用于处理字符串列表,我希望将其参数化,这样它将接受这个列表作为来自用户的参数。
下面是我的代码当前处理这个列表的方式:
set QUEUES=cars plans others
FOR %%q IN (%QUEUES%) DO Call :defineQueues %%q如何将此列表作为参数传递给QUEUES变量?
例如,我应该如何将它传递给这个脚本:
myScript.bat ?发布于 2015-03-02 12:52:51
您必须用引号将字符串括起来:
myScript.bat "cars plans others"那么%1就等于"cars plans others"
或%~1%以移除引号,而只获取cars plans others
否则,您将得到3个不同的参数值:
myScript.bat cars plans others
%1 => cars
%2 => plans
%3 => others发布于 2015-03-02 13:08:13
或者,如果只在命令行上传递队列值,则可以使用%*批处理文件操作符,它是对行中所有参数的通配符引用。
@echo off
FOR %%q IN (%*) DO echo %%q执行批处理文件如下:
x.bat cars plans others给出输出:
C:\junk>x.bat cars plans others
cars
plans
others
C:\junk>如果在命令中传递任何其他参数以及QUEUES元素,则为it is not that simple to 'shift' the other arguments out。
发布于 2017-12-07 10:04:24
您可以将其称为myScript.bat %QUEUES%,并且可以使用下面的代码在myScript.bat中获取它:
setlocal EnableDelayedExpansion
FOR %%q in (!%1!) DO echo %%qhttps://stackoverflow.com/questions/28810194
复制相似问题