2

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

enter image description here

Dean
  • 1,009
  • 3
  • 10
  • 19
  • 3
    Without knowing the contents of the batch script, this question is going to be impossible to answer :-) – Chris J Sep 02 '11 at 14:53
  • Surely I isolated it to one command only. – Dean Sep 02 '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 02 '11 at 15:03
  • 3
    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 02 '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 02 '11 at 15:28
  • I updated the question: The blockquote is the batch file – Dean Sep 02 '11 at 17:21

1 Answers1

12

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
Zoredache
  • 130,897
  • 41
  • 276
  • 420