aGerman wrote:It's still not exactly foolproof
Example argument (jeb):
one^&two"&threesimplified:
"& or
"&"
Thanks for that. Somehow thought it couldn't be that easy
And it takes down any following parameters as well.
Now, I don't think that'd be much of a problem in my particular use-case, though it's surely disappointing in a more academical sense. What I am actually after is basically "tokenize" the _beginning_ of the %* line in order to simulate an %* "shift" (since the built-in one only shifts the individual %1, %2, etc arguments, but not %* itself). Suppose I wanted to write a simple loggedrun.cmd which would save one line per run to a designated logfile, to be invoked like
loggedrun «logfile» «program-to-run» «program-arguments»
In a different better world, loggedrun.cmd could contain just
@setlocal
@set "logfile=%~1"
@rem _but_ 'shift' doesn't affect %*
@shift
@echo >>"%logfile%" %date% %time% starting: %*
@%*
@echo >>"%logfile%" %date% %time% done: %*
@endlocal
But of course this wouldn't work as such in the cmd world. Firstly, shift doesn't update %*, and then cmd has its own parsing rules which are different from everybody else's. In my example, what comes before «program-to-run» is obviously intended for the batch file, and would follow the cmd rules. However the «program-arguments» part would be under the control of the target program command-line-parsing logic, and it would need to be literally passed as such by the batch file.
Hope here was that combining the REM redirection trick for %*/%1/etc with some time-saving trick to extract the first "cmd-compliant" arguments would then allow me to remove those parts from %* and pass the rest thorugh unchanged.
Since my particular case only involves the first parameters which are largely under my/user's control, I could rule out "pathological" values for those parameters, and make it work under that assumption. That said, it would obviously be more "academically satisfying" if there was a general solution to that, more efficient than one temp file per %1/%2/etc argument.
Thanks again for all responses,
Liviu