how do i get a batch file to accept input from a txt file?

One way to do so would be to place the URLS in a text file like so:

www.google.com
www.yahoo.com

Then run the following batch

for /f %%a in (%1) do (
echo Pinging %%a...
ping %%a
)

and run it from cmd as pingme.bat URLs.txt

Alternatively, you may specify the text file's name within the batch, and run it without the parameter

for /f %%a in (URLs.txt) do (
echo Pinging %%a...
ping %%a
)

Here's another approach

This particular batch will pull from the list, and write to output.txt if the ping was successful

@ECHO OFF
SET output=output.txt
IF EXIST "%output%" DEL "%output%"
FOR /f %%a IN (URLs.txt) DO (
    CALL :ping %%a

)
GOTO :EOF

:ping
ping -n 1 %1 | find "Approximate round trip" >NUL || ECHO %1>>"%output%"

Hopefully that sets you in the right direction.

Tags:

Batch File