1
我有其中的實體的主機文件地址:主機並希望檢查給定的實體是否出現在hosts文件中。所以我寫了: 在hosts文件:在Windows 7中使用批處理腳本檢查主機文件的實體?
# Copyright (c) 1993-2009 Microsoft Corp.
129.0.2.2 tralala.com
而且在我的批處理腳本中,我寫道:
@if "%DEBUG%" == "" @echo off
@rem ############################################
@rem # Remove host from windows hosts file #
@rem ############################################
if "%OS%"=="Windows_NT" setlocal
:start
set "hostpath=%systemroot%\system32\drivers\etc\hosts"
goto addFindIPAddress
:addFindIPAddress
@rem set the string you wish to find
set find="129.0.2.2 tralala.com"
goto checkHosts
:checkHosts
for /f "tokens=*" %%a in (%hostpath%) do call :processline %%a
goto :mainEnd
:processline
set line=%*
if NOT line == find (
echo %line%
)
goto :eof
:mainEnd
if "%OS%"=="Windows_NT" endlocal
PAUSE
所以我想打印來自行查找,但沒有什麼不同的所有行偏偏讓我想知道是我的錯嗎?
另外,如果我設置'SETLOCAL EnableDelayedExpansion'不工作,然後 '如果不是!行!==!找到! (「那麼一切都很好。 – Xelian 2014-11-04 09:25:11