Running an external command in a cmd /K initiated environment the "usual" way is insecure.
Testing platform XP. Path contains brackets AND spaces:
Code: Select all
set "externalCommand=..\doskitXPserver2003 v0.1 (20190129)\Hello world ^^^!\doskitXPserver2003 v0.1 (20190129)\ext\eval\eval.EXE"
set "externalCommand"
echo.
Next fail with: The system cannot find the specified path OR X not recognized as an internal or external command, program or batch file.
Code: Select all
cmd /V:OFF /C "!externalCommand!" %arguments%
cmd /S /C ""!externalCommand!" %arguments%"
cmd /K ""!externalCommand!" %arguments%"
for /F "delims=" %%? in ( '"!externalCommand!" %arguments%' ) do echo.%%?
Note the last failing command using for. Many will use this when trying to read from an external program but it fails if externalCommand contains 'brackets' AND 'spaces' AND the 'parent process is cmd /K initiated' and therefore is completely insecure.
I found a few combinations that seem to work:
Code: Select all
"%externalCommand%" %arguments%
cmd /V:ON /C ""!externalCommand!" %arguments%"
start "" cmd /K ""!externalCommand!" %arguments%"
for /F delims^=^ eol^= %%r in ( 'cmd /V:ON /C ""!externalCommand!" %arguments%"') do echo.%%r