Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


enter image description here

share|improve this question
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
up vote 12 down vote accepted

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 (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
  • Use the full path to ping %SystemRoot%\system32\ping.exe
share|improve this answer
+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

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.