Start from the inside & work out. You’ve got too many layers executing now to see the real problem.
Also, using echo as a test harness doesn’t really give you enough intofrmation to see what’s happening.
My advice:
In general cmd.exe parses parameters on spaces, so if you want cmd to execute some program or cmd/bat file you wrote which takes 3 parameters, each of which may contain spaces, then you need to call your program like this
C:>Myprog.exe “parameter 1 with embedded spaces” “param2 is the same” “param 3”
One challenge doing it this way is that the quotes around parameters are passed into the program as well.
Create this simple test harness to see what I mean:
@echo off
:top
if {%1} =={} goto :EOF
echo param={%1}
shift
goto :top
Just save it as “TestHarness.cmd” & try calling it manually directly from the command line with various combinations of quotes, spaces, etc.
e.g.
C:>TestHarness.cmd abc def
C:>TestHarness.cmd "abc" "def"
C:>TestHarness.cmd "abc 1234" " def 567 "
C:>TestHarness.cmd "abc "" 1234" " def 567 "
Also make sure to see how it handles unmatched quotes so you’ll know what you have to do upstream of the call to handle any embedded quotes in the parameters you’d like to pass into your function.
When you get that behavior understood, then try
C:>cmd /c TestHarness.cmd …
for various combinations of paramters. You should see no difference except for certain pathological cases …
Depending on the needs of your parameters, you might want to spend some time understanding the difference between
C:>cmd /c TestHarness.cmd …
and
C:>cmd /s /c TestHarness.cmd …
/s was built to cover for cases where you want to cmd /c a compound command. In your situation you’d probably do better to create a cmd file to execute the compound. Note that switch order IS significant. /c (or /k) MUST be the final switch in the cmd call string. So /s must come before /c or /k.
Happy cmd-ing.