0

So basically, I have a script we use out on the field to do various functions. Part of the script will include a 'Debug Terminal' (For setting and checking variables, running functions directly etc.). I ran into some problems initially with echo and set commands (echo Hi would result in Hi is not recognized..; set would not process).

Here's what I wound up with:

:DebugConsole
%title%Debug Console %end%
:DebugConsoleTop
echo.
echo Enter a command or type 'exit' to finish.
set /p ConsoleInput=

if "%ConsoleInput%"=="exit" (
    goto DebugConsoleEnd
)

:if set used
if "%ConsoleInput:~0,3%"=="set" (
    echo %ConsoleInput%> "%datapath%\debugcmd.txt"
    set /p ConsoleOutput=<"%datapath%\debugcmd.txt"
    del /f "%datapath%\debugcmd.txt"
) else (
    :if echo
    if "%ConsoleInput:~0,4%"=="echo" (
        set "echofix=echo echo"
        ::set ConsoleInput=%ConsoleInput:%echofix%=%
        call set ConsoleInput=%%ConsoleInput:echo=%echofix%%%
        %ConsoleInput%
        goto DebugConsoleTop
)
    :all else
    FOR /F "delims=" %%i IN ('%ConsoleInput%') DO (
        SET ConsoleOutput=%%i
        echo %ConsoleOutput%
        pause
    )
)

%ConsoleOutput%

goto DebugConsoleTop

:DebugConsoleEnd
cls
exit /b

The problem I'm facing now is that you can not echo variables correctly. If I input "set var=test" and then "echo %var%" the output is "%var%" and not "test". However, if I input "%var%" i receive "test is not recognized.."

  • 3
    Beware of the [delayed expansion trap](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected/30284028#30284028) – Stephan Jan 26 '21 at 17:44
  • 3
    Within a block statement `(a parenthesised series of statements)`, `REM` statements rather than the broken-label remark form (`:: comment`) should be used because labels terminate blocks, confusing `cmd`. Labels are not allowed within blocks. – Magoo Jan 26 '21 at 17:53

0 Answers0