如果没有输入并输入按下,如何回显?

时间:2015-01-04 07:07:06

标签: batch-file

如果没有为选择输入并按下输入,如何设置Windows批处理脚本以回显某些内容。 E.g。

@echo off
title Thingy
:home
cls
echo.
echo =================
echo Thingy
echo =================
echo Choose An Option
echo =================
echo.
echo 1) Thing.exe With Stuff
echo 0) Exit
echo.
set /p web=Type an Option:
if "%web%"=="1" goto thing1

thing1:
set /p stuff="Enter stuff: "
thing.exe -load %stuff%

如果在“输入内容”中没有输入任何内容,只需按下输入,如何设置它以回显某些内容?

就像我想的那样 “echo没有输入输入,运行thing.exe没有任何东西”

2 个答案:

答案 0 :(得分:0)

if not defined web echo Nothing entered?&pause&goto home

if not defined web echo Nothing entered?&goto alabl\eljustbeforetheset_slash_p

if "%web%"=="" goto somewhere

请注意,按 Enter 会使变量保持不变所以

set "web=somedefaultvalue"
set /p "web=Some prompt text "
如果单独使用 Enter

可用于指定使用的默认值

set "web="
set /p "web=Some prompt text "
如果没有适用的默认值,

最好;它确保变量设置为 nothing ,而不是之前的任何值。

应该可以解决你的问题。

答案 1 :(得分:0)

您可以使用IF语句来确定输入是否为空:

set /p stuff="Enter stuff: "

IF "%stuff%"=="" (
    ECHO No input entered, running thing.exe with no args
    thing.exe
) ELSE (
    thing.exe -load %stuff%
)
相关问题