Windows batch file executes some commands that return output over and over

I tried to put commands that return output into batch file. When I run the batch file it executes the command over and over until I cancel with CTRL+C.

I observed this behavior in Windows CE, Windows XP, Windows 7 and Server 2003. At first I thought I made a mistake with LDIFDE but the same thing goes for PING.

Is there something I missed with batch scripting?

The file contains one line:

``````ping google.com
``````

-
Without knowing the contents of the batch script, this question is going to be impossible to answer :-) –  Chris J Sep 2 '11 at 14:53
Surely I isolated it to one command only. –  Dean Sep 2 '11 at 14:58
I am sorry I left this detail, It seems obvious - I placed only one command in the batch file to isolate the issue. –  Dean Sep 2 '11 at 15:03
That's odd, how are you executing the batch script? Without some sort of looping control structure it shouldn't be doing this ... –  Zypher Sep 2 '11 at 15:12
I've seen this before a long time ago, but I can't recall what it was. I think it had something to do with it not seeing ping as a command. I also see your runnign this from `D:\Desktop`. Post your batch file so we can help. –  Nixphoe Sep 2 '11 at 15:28

I.think you named your script `ping.bat` or `ping.cmd` and it is calling itself.

This happens because of a design decision that was introduced in DOS 2.0. On MS-DOS, Windows, and MS-DOS clones and derivatives, the current directory is first in the search path. When DOS is searching for a command it first checks to see if it an internal command, built into command.com (e.g. echo, copy) then it searches the filesystem. It always starts with the current directory, and then it looks in directories defined in the PATH variable.

You have a couple options:

• Rename the script.
• Simply include the file extension in your script so it is `ping.exe google.com`
• Use the full path to ping `%SystemRoot%\system32\ping.exe`
-
+1 Nice catch. Worked for me because I specifically DIDN'T do that. –  squillman Sep 2 '11 at 16:04
Wow, I would have never guessed that. Nice one! –  Brad Sep 2 '11 at 16:18
THATS IT! Good observation! I've been naming the batch files the same as the command. Thanks a lot! –  Dean Sep 2 '11 at 17:24