shell - 批量设置/p 不工作

标签 shell batch-file cmd set

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

即使我不使用 ENABLEDELAYEDEXPANSION 仅与 %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

命令 ECHO 决定:!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/

相关文章:

shell - SWT - 可靠地知道 shell 用户是否切换到另一个 shell 的事件

shell - 如何使用oozie执行shellScript

c - 从 Windows gui 程序输出到命令行

windows - DOSKEY 召回别名

windows - 从带有随机数字分隔符的字符串中获取变量 [cmd]

linux - 如何在 If else 情况下使用 shell 逻辑运算符

linux - 找到一个模式并修改下一行,而不修改文件中的其他内容。最好是基于 Linux 的命令(sed、awk 等)

bash - 如何使用脚本运行 MinGW?

batch-file - 使用带转义序列的 CALL ^

sql - table==1 是意外的此时批处理文件