Где у вас есть do ping -n 1 %%a >nul
Это берет вывод ping и выбрасывает его.
Я думаю ты хочешь
do ping -n 1 %%a >%LOGFILE%
Кроме того, вы вызываете несуществующий регион / подпрограмму (Logit)
@echo off SET LOGFILE=MyLogFile.log call :Logit >> %LOGFILE% exit /b 0 :Logit for /f "delims=" %%a in ( ' type "C:\Users\kelly\Desktop\Ping\computerlist.txt" ' ) do ping -n 1 %%a >nul && (echo %%a ok >> %LOGFILE% ) || (echo %%a failed to respond >> %LOGFILE% ) pause
(Непроверенные)
~~ Редактировать на основе комментария ОП и теперь протестировав ~~
Я думаю, это то, что вы ищете:
@ECHO OFF SET LOGFILE=logFile.txt SET TEMP_FILE=temp.txt SET PINGLIST=comps.txt REM contatenate log file echo. > %LOGFILE% for /f "delims=" %%a in (%PINGLIST%) do ( REM do ping and store response - using a temp file because we care about the response more than once. ping -n 1 %%a > %TEMP_FILE% REM append response to log file type %TEMP_FILE% >> %LOGFILE% REM from: https://stackoverflow.com/a/8531199 REM check if ping determined the host is unreachable by searching the output findstr /c:"Destination host unreachable" /c:"could not find host" %TEMP_FILE% > NUL REM if the errorlevel is at least 1 (unsuccessful at finding string) if errorlevel 1 ( REM then must have reached host echo %%a is ok >> %LOGFILE% ) ELSE ( REM else, we found the string that sais we cannot reach the host echo %%a is UNREACHABLE^! >> %LOGFILE% ) REM cleanup del %TEMP_FILE% ) exit /b