在Windows 7上工作的bat脚本,但在Windows 2k8上没有

时间:2013-06-13 05:32:38

标签: windows batch-file cmd

我有一个可以在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."

2 个答案:

答案 0 :(得分:0)

您将哪个名称称为批处理文件?

以下是需要注意的几点:

如果ERRORLEVEL = 1转到VIP_NOT_FOUND

以上情况并非如此 - 下面是一种方法:

if ERRORLEVEL 1 goto VIP_NOT_FOUND

以下这一行需要goto:EOF,如图所示。

echo "testing works" >> testing.txt
goto :EOF

答案 1 :(得分:0)

我找到了解决方案。

是从这个改变

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

到这个

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