HFShak, я был несколько ошарашен, когда увидел вывод Вашей «nslookup.exe»: в stdout в Ansi, в stderr — в OEM.
Попробуйте очередной вариант:
читать дальше »
Код:
![Выделить весь код](images/misc/selectcode.png)
@echo off
setlocal enableextensions enabledelayedexpansion
set sFileSource=%~1
set sLog=%~2
call :GetTemporaryName
set sStdOut=%TemporaryName%
call :GetTemporaryName
set sStdErr=%TemporaryName%
if defined sFileSource (
if defined sLog (
if exist "%sFileSource%" (
>nul copy nul "%sLog%"
for /f "usebackq tokens=*" %%i in ("%sFileSource%") do (
echo Processing [%%i]...
set sName=
set sAddress=
set bCriticalError=
nslookup.exe "%%i" 1>"%sStdOut%" 2>"%sStdErr%"
<"%sStdErr%" set /p sError=
if defined sError (
if "!sError:~0,3!" equ "***" (
>>"%sLog%" echo %%i = !sError!
set bCriticalError=1
)
)
if not defined bCriticalError (
set /a iCount = 0
for /f "usebackq skip=3 tokens=2 delims=,: " %%j in ("%sStdOut%") do (
set /a iCount += 1
if !iCount! equ 1 set sName=%%j
if !iCount! equ 2 set sAddress=%%j
)
>>"%sLog%" echo !sName! = !sAddress!
)
)
) else (
echo File with Names list [%sFileSource%] not found
)
) else (
call :Usage
exit /b 1
)
) else (
call :Usage
exit /b 1
)
endlocal
exit /b 0
rem ==========================================================================
rem ==========================================================================
:Usage
echo Usage: %~nx0 ^<Names list^> ^<Log file^>
exit /b 0
rem ==========================================================================
rem ==========================================================================
rem Функция GetTemporaryName()
rem
rem Серый форум / CMD/BAT: генерация пути для временного файла или папки
rem (http://forum.script-coding.com/viewtopic.php?id=6259)
rem ==========================================================================
:GetTemporaryName
setlocal enableextensions enabledelayedexpansion
:NextName
set sTempName=%temp%\temp%random%.tmp
if exist "%sTempName%" goto :NextName
set sProcName=%~0
endlocal & set %sProcName:~4%=%sTempName%
exit /b 0
rem ==========================================================================