0

因此,我创建了一个 .bat 文件,用于检查一系列标准服务器以查看它们是否已启动,并且我想在完成后根据结果创建选项。批次运行良好,直到我输入菜单。哈普?

@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
4

2 回答 2

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
于 2013-08-23T06:10:32.710 回答
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?
于 2013-08-23T08:43:17.597 回答