Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
miskox
- Posts: 668
- Joined: 28 Jun 2010 03:46
#1
Post
by miskox » 13 Jan 2015 06:29
I have this batch file:
Code: Select all
@echo off
echo Params1=%*
shift
echo Params2=%*
shift
echo Params3=%*
And I execute it with parameters 1 2 3 4 5:
Code: Select all
c:\abc.cmd 1 2 3 4 5
Params1=1 2 3 4 5
Params2=1 2 3 4 5
Params3=1 2 3 4 5
c:\
I want this:
Code: Select all
c:\abc.cmd 1 2 3 4 5
Params1=1 2 3 4 5
Params2=2 3 4 5
Params3=3 4 5
c:\
I want first parameter (%1) removed and then I want to pass all other parameters (there can be n parameters).
Any ideas?
Thanks.
Saso
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 13 Jan 2015 07:25
I swear we just covered this question on the forums a few weeks ago.
-
miskox
- Posts: 668
- Joined: 28 Jun 2010 03:46
#3
Post
by miskox » 13 Jan 2015 07:34
I will search for the answer....
Sorry.
Thanks.
Saso
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 13 Jan 2015 08:38
Code: Select all
@echo off
set "tokens=1"
set "count=2"
set "parms1=%*"
:LOOP
FOR /F "tokens=%tokens%* " %%G in ("%*") do set "parms%count%=%%H"
IF DEFINED parms%count% (
set /a tokens+=1
set /a count+=1
GOTO LOOP
)
set parms
pause
output
Code: Select all
C:\BatchFiles\parms>parms.bat 1 2 3 4 5 6 7 8 9 10 11 12
parms1=1 2 3 4 5 6 7 8 9 10 11 12
parms10=10 11 12
parms11=11 12
parms12=12
parms2=2 3 4 5 6 7 8 9 10 11 12
parms3=3 4 5 6 7 8 9 10 11 12
parms4=4 5 6 7 8 9 10 11 12
parms5=5 6 7 8 9 10 11 12
parms6=6 7 8 9 10 11 12
parms7=7 8 9 10 11 12
parms8=8 9 10 11 12
parms9=9 10 11 12
Press any key to continue . . .
-
miskox
- Posts: 668
- Joined: 28 Jun 2010 03:46
#6
Post
by miskox » 14 Jan 2015 07:57
Thanks. I will study your solution.
Saso
-
Aacini
- Expert
- Posts: 1932
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#7
Post
by Aacini » 14 Jan 2015 13:12
The method below allows to use parameters enclosed in quotes and wild-cards:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem The line below ends in a space
set parms=%*
set parms1=%*
set count=1
:loop
set parms=!parms:*%1 =!
if not defined parms goto endLoop
set /A count+=1
set parms%count%=%parms%
shift
goto loop
:endLoop
set parms
Output:
Code: Select all
C:\> test 1 "2" 3 "4 a b c" 5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms1=1 "2" 3 "4 a b c" 5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms10=10???.?? 11 12
parms11=11 12
parms12=12
parms2="2" 3 "4 a b c" 5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms3=3 "4 a b c" 5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms4="4 a b c" 5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms5=5 "6 < | > &" 7 8*.* 9 10???.?? 11 12
parms6="6 < | > &" 7 8*.* 9 10???.?? 11 12
parms7=7 8*.* 9 10???.?? 11 12
parms8=8*.* 9 10???.?? 11 12
parms9=9 10???.?? 11 12
Antonio