-2

my batch file is ProcessMe.bat

the Command is this

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

the parameters order is not fixed

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   

and parameters are coming in the same format single - and double --

I want to read these parameters in my .bat file

I tried these but non worked

echo %--size%

echo %-size%

echo %size%

echo --size

echo -size

echo size

echo %--size

echo %-size

echo %size

how can I get parameters values in .bat file?!

asmgx
  • 7,328
  • 15
  • 82
  • 143
  • @michael_heath this is just use parms order, in my case order is exchangable. – asmgx May 24 '20 at 09:19
  • 1
    Perhaps an answer at [Find value of command line argument in batch file](https://stackoverflow.com/a/55596264/9012170). That does any order. – michael_heath May 24 '20 at 09:30
  • I think you are mistaking batch arguments for powershell arguments. In batch-files, arguments are passed through number variables recognized by a single `%` like `%1` where `%1` is the first argument, `%2` the second and so on where `%0` is teh path of the batch file. – Nico Nekoru May 24 '20 at 22:50
  • There is no `params` function in powershell. That is a powershell command – Nico Nekoru May 24 '20 at 22:52

1 Answers1

0

With each switch having only one value, This one is very easy. Use shift and assign the value to the switch name until all Params have been processed with the aid of a loop

@Echo off
Setlocal EnableExtensions EnableDelayedExpansion
Call :PROCESS %*
For %%A in (Type tag size color) DO Set %%A
Pause
Exit /B
:PROCESS
    IF "%~1" == "" Exit /B 0
    Set "PARAM=%~1"
    Set "PARAM=!PARAM:-=!"
    SHIFT
    Set "!Param!=%~1"
    SHIFT
Goto :PROCESS
T3RR0R
  • 2,747
  • 3
  • 10
  • 25