[Edited]
Based on what I understand, you want to execute a command written in a file, store that command in a variable, and then execute it. Let's assume the file contains this command:
commad.txt:
cmd.exe /c "for /l %i in (1 1 10) do @echo %i"
and the script:
@echo off
set "command="
set "args="
for /f "tokens=1,*" %%i in (command.txt) do (
set "command=%%i"
set "args=%%j"
)
REM Check if command was found.
if defined command (
REM execute command.
%command% %args%
REM Destroy file contents.
type nul >command.txt
) else (
echo command not found.
exit /b 1
)
exit /b 0
1. Set variables command and args as empty.
2. Read the first word from command.txt as command, the rest as args.
3. If a command is found, run it with its arguments.
4. Destroy the file contents.
5. If no command, show an error message and exit with exit code 1.
echo
in your code, meaningecho is off
originates from executing%cmd%
(it can't be empty, else you wouldn't get a response at all). Replace%cmd%
withset cmd
to verify the contents of%cmd%