所以,我创建了一个.bat文件,用于检查一系列标准服务器是否已启动,我希望在完成后根据结果创建选项。批次运行很好,直到我扔进菜单。 HALP?
@echo off
:top
cd\
cls
SET site=%1
SET cc=%2
if "%site%" equ "" set /P site=Site Number:&SET /P cc=Country Code (US if left blank):
if [%cc%]==[] set cc=us
echo.
:startloop
set #=%site%
:subloop
set site=s0%site%
echo Checking %site%.%cc%
echo.
for %%i in (saps01 saps02 vsrv01 vsrv02) do call :main %%i
echo.
goto end
:main
set sys=%1.%site%.%cc%
set state=down
ping -n 1 -w 2000 %sys% | findstr "Reply" >Nul
if %errorlevel% equ 0 set state=up
if %state% equ "down" goto main2
:main2
echo %1 is %state%
goto end
:end
set /p menu=Select an option:
echo 1) option 1
echo 2) option 2
if %menu%=1 echo 1
if %menu%=2 echo 2
答案 0 :(得分:2)
我会在选项标题后移动set
命令并使用==
代替=
echo 1) option 1
echo 2) option 2
set /p menu=Select an option:
if %menu%==1 echo 1
if %menu%==2 echo 2
答案 1 :(得分:0)
我已修改您的代码以简化它 - 看看它是否对您有所帮助:
@echo off
:top
cd\
cls
SET "site=%1"
SET "cc=%2"
if "%site%" equ "" (
set /P "site=Site Number: "
set /P "cc=Country Code (US if left blank): "
)
if "%cc%"=="" set "cc=us"
:startloop
set #=%site%
:subloop
set site=s0%site%
echo Checking %site%.%cc%
echo.
for %%i in (saps01 saps02 vsrv01 vsrv02) do (
ping -n 1 -w 2000 %%i.%site%.%cc% >nul && (echo %%i is up) || (echo %%i is down)
echo.
)
echo 1) option 1
echo 2) option 2
set /p "menu=Select an option: "
if "%menu%"=="1" echo 1
if "%menu%"=="2" echo 2
goto :where?