"David Wang [Msft]" wrote:
>How about this:
>
>@echo off
>if /I ?%1? NEQ ?/log? goto :LogIt
>set LogCmd=%*
>echo on
>call %0 %LogCmd:/log=% >"%~dpn0.log" 2>&1
>set LogCmd=
>goto :eof
>:LogIt
>REM the start of your batch file
>
>
>So, "/log" can be anywhere in the parameter, and it is not in %* ... of
>course, it has that one variable. I guess it's either no new variables but
>%* is changed, or one new variable and %* is unchanged. If %*:/log=%
>worked, this would be perfect. I happen to have a parameter parser that is
>not order specific, so I like allowing /log to be anywhere.
>
I have no time for further checking, but this should give position inde-
pendence of the /log argument. If there are quoted paramters the
replacement of at least the " is neccessary, otherwise the if will give
an error.
@echo off & setlocal
set LogCmd=%*
set LogChk=%*
set "LogChk=%LogChk:"=¬%"
set "LogChk=%LogChk:^=^^%"
set "LogChk=%LogChk:&=^&%"
set "LogChk=%LogChk:<=^<%"
set "LogChk=%LogChk:>=^>%"
set "LogChk=%LogChk

=^(%"
set "LogChk=%LogChk

=^)%"
set "LogChk=%LogChk:|=^|%"
if /I "%LogChk%" EQU "%LogChk:/log=%" goto :LogIt
echo on
call %0 %LogCmd:/log=% >"%~dpn0.log" 2>&1
goto :eof
:LogIt
REM the start of your batch file
>Ahh... one of the fun parts of tweaking with batch scripting to get the best
>solution with least tradeoffs. :-) This is also one of the reasons I like
>this newsgroup now that I've found it.
>
ACK
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm