0

我有一个脚本可以在 Windows 7 上运行,但不能在 2k8 上运行,抛出找不到文件的异常。

@echo off
REM #Testing FIND in IPCONFIG
SET VIPTHATWORKS="11.11.11.11"
SET VIPTHATFAILS="192.168.122.17"

ipconfig /all | find %VIPTHATWORKS%
if ERRORLEVEL = 1 goto VIP_NOT_FOUND

REM #We are here becuase the find returned a result.
REM #It is safe to execute the rest of the application.
REM #EXECUTES THE SCRIPT HERE

echo "testing works" >> testing.txt

:VIP_NOT_FOUND
REM #This part of the script is where you would handle any
REM #error logging or other admin related
echo "Could not find a VIP. - Exiting"
echo "end of script reached."
4

2 回答 2

0

我找到了解决方案。

就是要从这个改变

ipconfig /all | find %VIPTHATWORKS%
if ERRORLEVEL = 1 goto VIP_NOT_FOUND

对此

ipconfig /all | findstr %VIPTHATWORKS%
if ERRORLEVEL = 1 goto VIP_NOT_FOUND
于 2013-06-14T06:25:34.683 回答
0

你给你的批处理文件起什么名字?

以下是需要注意的几点:

如果 ERRORLEVEL = 1 转到 VIP_NOT_FOUND

上述内容并不完全符合预期 - 一种方法如下:

if ERRORLEVEL 1 goto VIP_NOT_FOUND

下面的这一行需要一个 goto :EOF,如图所示。

echo "testing works" >> testing.txt
goto :EOF
于 2013-06-13T07:44:17.373 回答