我已经编写了简单的脚本来启动/重新启动程序,但是没有做出确认重新启动的决定,因为无论我在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
输出中的命令
ECHO Decision: !deci! .
始终为Decision .
我有Windows 8.1 x64
最佳答案
SET /p deci = R:
^ This space is included in the variable name
因此,您以一个名为
!deci !
的变量结尾。更好地使用SET /p "deci= R:"
关于shell - 批处理集/p不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29822680/