Wo du hast do ping -n 1 %%a >nul
Das heißt, die Ping-Ausgabe nehmen und wegwerfen.
Ich denke du willst
do ping -n 1 %%a >%LOGFILE%
Sie rufen auch eine nicht vorhandene Region / Unterprogramm auf (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
(ungetestet)
~~ Bearbeiten basierend auf dem Kommentar von OP und nun ~~ getestet
Ich denke, das ist was Sie suchen:
@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