I'll bet the problem is the NAME of your batch file... You didn't name it "ping.bat" perhaps? If you did, all you would accomplish is a looping file that does nothing but echo lines and call itself again in an infinite loop. Since there is no @ECHO OFF statement leading, each line echoes which you redirect into the output file. If you let it go, and did not manually BREAK the program to stop it, it would go forever until it ate up all of your disk space. Name your batch file "pingthem.bat" instead and you will find it will run correctly. Since ping is a program, you should use CALL to insure control returns to your batch file, however it is optional for a program, but mandatory .to daisy chain batch files. Here is a 3 line example that I have used on a LAN to test things, named "pingthem.bat" of course:
@echo off
for %%x in ( 0 1 2 3 4 5 6 7 8 9 ) do ping 192.168.0.%%x > pingthem.txt
for %%x in ( 10 11 12 13 14 15 ) do ping 192.168.0.%%x >> pingthem.txt
This sequence pings every IP address from 0 through 15 in the 192.168.0.XXX range and echoes the results into the "pingthem.txt" file.
I'll bet your naming of your batch file is your problem...
By the way, your line of :
ping www.yahoo.com >>C:\ping.txt
would be better expressed this way:
call ping.exe yahoo.com >> pingthem.txt
By using the optional EXE extension (IS it an EXE or a COM file? I forget) and the complete file name, you prevent any ambiguity when you have COM, EXE and BAT files of the same name. The problem is this: the command processor looks for COM, EXE and then BAT files in that order, true, but it searches the LOCAL directory for all 3 first before going through the entire PATH looking for the ambiguous file name. So, if there is a BAT file in the local directory, it will be found before the path is search for COM files, then EXE files, and finally BAT files. So, if you had a "ping.bat"
file in the current directory, even though it violates COM EXE BAT precedence, it is found and executed BEFORE the full path is searched for COM files and EXE files. Blame it all on Bill Gates. When he set precedence of COM, EXE and then BAT files, he should have done all of the path first for COM files, then EXE and finally BAT files. Why he made an exception for the current directory is beyond ME... Take a lesson here... DO NOT name batch files with actual program names. Always use an unambiguous name that can NOT be confused with any file name. One last thing, what version of windoze you are using determines whether you have a true command processor or an emulator, which ALSO can affect the precedence. As I recall, the last version with a true command processor was NT/2000. Anything newer is only a MSDOS emulator which has some very subtle differences which can cause unintended consequences. Not all MSDOS programs will run in an emulator, especially ones which deal with the hardware directly.