Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch set /p not working

I have made simple script to start/restart program, but decision to confirm restarting is not made, because 'deci' is empty whatever I write in set /p command.

The same is even when I not use ENABLEDELAYEDEXPANSION just with %deci%

@echo off
cls
ECHO Preparing to start
tasklist /FI "IMAGENAME eq n.exe" 2>NUL | find /I /N "n.exe">NUL
IF "%ERRORLEVEL%"=="0" (
    SETLOCAL ENABLEDELAYEDEXPANSION
    ECHO Programm is running
    ECHO "Do you want to restart program (y\n)"
    SET /p deci = R:
    ECHO Decision: !deci! .
    IF "!deci!" EQU "y" (
        ECHO Restarting
        taskkill /f /im "n.exe"
        start nginx.exe
    ) ELSE (
        ECHO Aborted, but program still running.
    )
) ELSE (
    ECHO Not running. Starting
    start n.exe
)

PAUSE

Command ECHO Decision: !deci! . in output always is Decision .

I have Windows 8.1 x64

like image 263
Levvy Avatar asked Sep 12 '25 10:09

Levvy


1 Answers

SET /p deci = R:
           ^ This space is included in the variable name

So you end with a variable named !deci !. Better use

SET /p "deci= R:"
like image 137
MC ND Avatar answered Sep 15 '25 10:09

MC ND