Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let´s say I have here a text file with some computer names (each line == 1 name):


Is it possible to create a batch file that is pinging all of these computers? And actually a ping is a big output. I don't need the time or other information; I just would like to know reachable or not. Any ideas?

It´s working now! The problem was like fox said, that I named my batch file as ping.bat and ping is also a command so this did not work out. I renamed my batch file and now everything is fine.

share|improve this question

migrated from Apr 30 '13 at 12:52

This question came from our site for professional and enthusiast programmers.

Look at the for command, especially the file parsing mode. –  Damien_The_Unbeliever Apr 29 '13 at 10:54

2 Answers 2

up vote 7 down vote accepted

Try this:

@echo off
for /f "delims=" %%a in (computerlist.txt) do ping -n 1 %%a >nul && (echo %%a ok) || (echo %%a failed to respond) 

If you have to use a filename or path with spaces or odd characters then Instead of (computerlist.txt) use ( ' type "c:\folder\computer file.txt" ' )

share|improve this answer
I see the cmd is popping up very shortly and then it´s gone. Even with pause or sleep at the end I dont see any output. –  sabisabi Apr 29 '13 at 11:36
Try the edited code above which includes the OK response. –  foxidrive Apr 29 '13 at 12:39
No change at all, this is weird. I copy exact the same code (ok I change the filename) as you posted there into a textfile -> I save this as a .bat and after that I start the .bat file -> cmd popping up and then it´s gone without any output. I´m using win xp, could this be a problem? –  sabisabi Apr 29 '13 at 13:36
Your path\filename probably contains spaces. Instead of (computerlist.txt) use ('type "c:\folder\computer file.txt" ') –  foxidrive Apr 29 '13 at 13:46
That is your mistake. Always remember that when naming a batch file you should avoid using the name of a command. In your case the ping command inside the batch file is executing the ping batch file and not the ping command. –  foxidrive Apr 30 '13 at 9:12
@Echo OFF

For /F "Usebackq Delims=" %%# in (
) do (
    Echo [+] Pinging: %%#

    Ping -n 1 "%%#" 1>nul && (
        Echo     [OK]) || (
        Echo     [FAILED])



[+] Pinging:

[+] Pinging: ffff
share|improve this answer
When I start my .bat I see the output [+] Pinging: computerA , but then the window is disappearing. –  sabisabi Apr 29 '13 at 11:38
You'he vopied my script as is without several changes? –  ElektroStudios Apr 29 '13 at 12:43
Well I changed the name of the file, but that´s it –  sabisabi Apr 29 '13 at 13:34
@sabisabi: start the batch file "manually" from an existing command prompt you you'll be able to read the error message. Don't "double click" batch files that you have to test. –  a_horse_with_no_name Apr 29 '13 at 14:10
@a_horse_with_no_name if I start the .bat file via cmd (ping.bat) -> there is no new window and my cmd is closing itself without any message –  sabisabi Apr 29 '13 at 14:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.