批处理文件关闭而不是执行 GOTO 命令

Batch file closes instead of doing GOTO command

我的代码尚未完全完成,但在进行选择后按回车键后测试它关闭了。然后应该使用 goto 并转到 :WEBSITECHECK 但关闭。

这是我的代码:

echo Welcome! This program will check if a website or server is up.
echo
echo Shortcuts:
echo 'fb' for facebook.com
echo 't' for twitter.com
echo 'insta' for instagram.com
echo 'yt' for youtube.com
echo 'r' for reddit.com 

echo -------------------------------------------------------------
echo Type '1' to check a website or '2' to check an I.P. address.
echo -------------------------------------------------------------

set type=
set /p %type% = Enter selection:
 if %type%==1 GOTO WEBSITECHECK
 if %type%==2 GOTO IPCHECK

:WEBSITECHECK

set site=
set /p %site% = Enter URL or shortcut:

REM shortcuts

if %site% == fb ping facebook.com
if %site% == t ping twitter.com
if %site% == insta ping instagram.com
if %site% == yt ping youtube.com
if %site% == r ping reddit.com

if %site% !==! fb GOTO OTHERSITE
if %site% !==! t GOTO OTHERSITE
if %site% !==! insta GOTO OTHERSITE
if %site% !==! yt GOTO OTHERSITE
if %site% !==! r GOTO OTHERSITE

:OTHERSITE

ping %site%

:IPCHECK

pause

我已经在上面的评论中指出了你的问题,所以这里有一个例子,说明如何在这样的场景中使用 choice。:

@echo off & set cnt=
setlocal enabledelayedexpansion
choice /C 12 /M "Site or IP?:
set "chose=%errorlevel%"

:: you can have a maximum of 9 sites!
set "select1=youtube.com facebook.com twitter.com instagram.com reddit.com"

:: You can have a maximum of 9 IP's!
set "select2=8.8.8.8 127.0.0.1 10.1.4.5"

for %%i in (!select%chose%!) do (
    set /a cnt+=1
    echo !cnt!^) %%i
    set "_opt!cnt!=%%i"
)
for /l %%c in (1,1,%cnt%) do set ch=!ch!%%c
choice /C %ch% /M "Enter Selection:"
ping !_opt%errorlevel%!
pause