Is it possible to filter list of arguments in windows batch file?
Assuming it is called like:
file.cmd arg1 --unwanted arg3
It should call some other executable (hardcoded) without the argument string --unwanted:
some.exe arg1 arg3
I only know the name of the argument, it can be passed as any argument in the list. It may not exist on argument list, and the all arguments should be passed unmodified. Number of arguments may vary.
More examples (what’s called -> what should be called in result)
file.cmd arg1 arg2 -> some.exe arg1 arg2
file.cmd --unwanted -> some.exe
file.cmd --unwanted arg2 -> some.exe arg2
file.cmd arg1 --unwanted -> some.exe arg1
Moving from unix shell scripting windows batch files are black magic to me 🙂
This prints:
Edit:
prints
meaning “arg1=foo” is broken, you can switch the for loop to
for /F "tokens=%var% delims= " %%A in ('echo.%*') do (to get it working, but that breaks arg1=foo and arg3=”bar”This is a known problem with batch files, once you start messing with strings things are going to get screwed up in some configuration since there is always some character that is going to mess things up (%,!,”,^,&,|,<,>,space etc)