批量设置/ p不起作用

Lev*_*vvy 2 shell cmd batch-file set

我已经制作了简单的脚本来启动/重启程序,但是没有做出确认重启的决定,因为无论我在set/p命令中写什么,'deci'都是空的.

即使我没有使用%deci%的ENABLEDELAYEDEXPANSION也是如此

@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
Run Code Online (Sandbox Code Playgroud)

ECHO Decision: !deci! .输出中的命令始终是Decision .

我有Windows 8.1 x64

MC *_* ND 8

SET /p deci = R:
           ^ This space is included in the variable name
Run Code Online (Sandbox Code Playgroud)

所以你以一个名为变量的结尾!deci !.更好用

SET /p "deci= R:"
Run Code Online (Sandbox Code Playgroud)