Liviu wrote:I remember that thread. Don't know that the following would make much sense to me on a first reading otherwise

- "setlocal disableExtensions"
- "for %%a in (%%a)"
- the space after the "." in "do rem . %*."
- the magical numbers in "args=!args:~7,-2!"
My original solution has one drawback with %%a.
If the parameter itself contains %%a this is expanded, but also %%~fa or %%~da, someone (suppose it was Aacini) has the clever idea to disable the extensions,
so only %%a is expanded, the %%~ variants are unchanged.
Therefore the %%a is expanded to %%a by "for %%a in (%%a)".
The space after "." is necessary as REM has a special parser, it parses the frist token after REM to recognize if there is /?.
So the space move the %* after the first token, the trailing character is necessary, to avoid multiline problems with an ending caret character in the parameter.
The magical numbers in "args=!args:~7,-2!" is simply the result of the prompt output
Code: Select all
#REM[space].[space]<%*paramter>.[space]
carlsomo wrote:It is certainly an advantage to not have to worry about placing escape chars. I just wish there was a way to get the all command line args with poison chars but without using a temp file.
Currently I can't see any possible way for this, because:
The only ways to read %* or any other thing you need a SET or a FOR-loop.
SET can't work, as you can build paramters, which always fails, like "&"&
If you place it in the FOR command part, you can break it with the same poisen string, and you can't avoid this.
Therefore you need a variant where the expanded %* will be ignored completely by the parser, so the REM %* seems to be appropiated.
But there are still two problems left.
It's not possible to catch any <CR> characters embedded in the parameter, as just after the percent expansion all CR's are removed.
With embedded linefeeds in the parameter you can break the complete code(code injection).
Like
Code: Select all
test.bat this is my parameter ^
echo hello ^> CON ^
rem -
jeb