我已经制作了简单的脚本来启动/重启程序,但是没有做出确认重启的决定,因为' deci'无论我在set / p命令中写什么都是空的。
即使我没有使用%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
输出中的命令ECHO Decision: !deci! .
始终为Decision .
我有Windows 8.1 x64
答案 0 :(得分:8)
SET /p deci = R:
^ This space is included in the variable name
所以你以一个名为!deci !
的变量结束。更好地使用
SET /p "deci= R:"