Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
3  
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
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 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
show 1 more comment

2 Answers

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 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
share|improve this answer
1  
+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
add comment

@ping www.google.com > nul
In this way you send the output the blackhole thats called nul (null).

share|improve this answer
1  
I fail to see how this solves the problem –  Holocryptic Sep 2 '11 at 17:34
1  
-1 All this does is eat the output. That's not at all what the OP was asking about. –  squillman Sep 2 '11 at 17:46
add comment

Your Answer

 
discard

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.