Question

What I would like to do is write a generic execute command wrapper "method" in a batch file. Here is an example of the method I want:

:EXEC_CMD
set cmd=%~1
echo Executuing cmd: %cmd%
CALL %cmd%
rem *** check some stuff and end

This works for simple commands but when the commands I want to execute has parameters and they require quotes, then things do not work so well:

cmd to execute:

:EXEC_CMD "test.bat "arg1" "arg 2" "a r g 3""

output:

Executing cmd: test.bat "arg1" "arg

what is the best way to get the above to execute any command I give it? I tried escaping the nested double quotes and placing quotes in different spots but nothing has worked so far.

Was it helpful?

Solution

:EXEC_CMD
set cmd=%*
echo Executuing cmd: %cmd%
CALL %cmd%
rem *** check some stuff and end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top