Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用单参数和双参数读取批处理参数-_Batch File - Fatal编程技术网

Batch file 使用单参数和双参数读取批处理参数-

Batch file 使用单参数和双参数读取批处理参数-,batch-file,Batch File,我的批处理文件是ProcessMe.bat 命令是这样的 ProcessMe -color blue -type high --size large --tag gift 参数顺序不是固定的 ProcessMe -type high --tag gift --size large -color blue ProcessMe --tag gift -color blue --size large -type

我的批处理文件是ProcessMe.bat

命令是这样的

ProcessMe   -color  blue    -type  high    --size  large    --tag  gift
参数顺序不是固定的

ProcessMe     -type  high  --tag  gift  --size  large  -color  blue    

ProcessMe     --tag  gift   -color  blue   --size  large   -type  high

ProcessMe     --size  large    -type  high  -color  blue   --tag  gift   
参数的格式是一样的,单参数和双参数--

我想在.bat文件中读取这些参数

我试过了,但没用

echo %--size%

echo %-size%

echo %size%

echo --size

echo -size

echo size

echo %--size

echo %-size

echo %size

如何在.bat文件中获取参数值

每个开关只有一个值,这一个非常简单。 使用shift并将该值指定给开关名称,直到在循环的帮助下处理完所有参数

@Echo关闭
Setlocal EnableExtensions EnableDelayedExpansion
呼叫:进程%*
对于%%A in(键入标记大小颜色),请设置%%A
暂停
退出/B
:进程
如果“%~1”==”退出/B 0
设置“参数=%~1”
设置“参数=!参数:-=!”
移位
设置“!Param!=%~1”
移位
后藤:过程

@michael_heath这只是使用parms订单,在我的情况下,订单是可交换的。也许可以在以下地址找到答案。这是任意顺序的。我认为您将批处理参数误认为是powershell参数。在批处理文件中,参数通过单个
%
识别的数字变量传递,例如
%1
,其中
%1
是第一个参数,
%2
是第二个参数,依此类推,其中
%0
是批处理文件的路径。powershell中没有
params
函数。这是一个powershell命令