passing on unused parameters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alasdair
Posts: 4
Joined: 27 Sep 2007 04:20

passing on unused parameters

#1 Post by alasdair » 19 Oct 2007 11:36

I have a batch file (lets call it doit.bat) which calls doit.exe. doit.bat wants to sonsume the first 3 arguments, and pass any remaining ones to doit.exe. On unix I am used to shifting away the used arguments and hten passing on $*. However in dos %* seems unaffected by shift? is this really the case or am I missing somehting

doit.bat

set arg1=%1
shift
set arg2=%2
shift
.. do some stuff

doit.exe %3 %4 %5 ( there may be none or 20)

seems a bit silly to just specify %3 %4 %4 ... %20 .. %999

jeb
Expert
Posts: 917
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 19 Oct 2007 13:22

Hi alasdair,

you are right, %* is unaffected by shift
But it exist another possible way.
Not perfect, but better than %4 %5 %6 ... %9
%999 does not work, because only %1 .. %9 are defined
%10 expands to "%1" and "0"

The other way
for /f "tokens=3*" %%a in ("%*") do doIt.exe %%b

Problems exists if one of the parameters %1 .. %n are of the form "a b" or
a;b, but if you only use "normal" paramters all works fine.

hope it helps
jeb

alasdair
Posts: 4
Joined: 27 Sep 2007 04:20

#3 Post by alasdair » 22 Oct 2007 01:32

you are quite right, that works fine. Thanks a lot.

Post Reply