Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I created a .BAT file in Windows 7 that has the following line:

PING XXX.XXX.XXX.XXX -t

(XXX replaces the actual IP number). However, when I double click on this batch file, I can see the PING command repeatedly being executed in a loop. I even tried to rename the ping.BAT to ping.CMD but the result is the same.

I want to avoid writing PING command through the Command Prompt, which is why I created the batch file. I don't know why the PING command is being continuously called when the same statement is put in a batch file.

share|improve this question
1  
Actually repeating or you see it pinging forever? Because that's what -t does. –  ta.speot.is Jun 18 '11 at 3:52
    
ping 127.0.0.1 -t <-- from cmd prompt, it does repeatedly. and that's not in a batch file (tested in win xp) –  barlop Jun 18 '11 at 3:56
    
you're supposed to put the - switch before the host anyway. ping -t 127.0.0.1 but does the same thing. and is meant to. why use -t if you don't want infinite, see ping -? so your question is profoundly strange –  barlop Jun 18 '11 at 3:58
    
"I don't know whey the PING command is being continuously called when the same statement is put in a batch file." <-- do you stand by this? –  barlop Jun 18 '11 at 4:00
    
I still haven't found a solution. I see the PING command being repeatedly called without any result. –  pradeetp Jun 19 '11 at 17:04

7 Answers 7

The -t parameter makes the ping continuous.

Maybe remove the -t parameter and then tell your batch script to wait for you to press enter before killing the cmd screen.

Haven't used windows in a while but this should work:

ping xxx.xxx.xxx.xxx
pause
exit
share|improve this answer
    
removing -t didn't work. Could you please post the script? –  pradeetp Jun 19 '11 at 17:04
    
@pradeetp added some code above –  MaxMackie Jun 19 '11 at 19:22

I had the same problem,

ping.bat contained several lines of ping command

ping host1
ping host2
ping host3
...

output in cmd shell looked as below and continued in a loop on and on until the break with ctrl+C

c:\ping host1    
c:\ping host1    
c:\ping host1    
c:\ping host1    
c:\ping host1
...

c:\ping host1
^CTerminate batch job (Y/N)?

To solve it, just rename the ping.bat, so it doesn't call itself in the batch file or use ping.exe as the command in the batch file

ping.exe host1
ping.exe host2
ping.exe host3
...
share|improve this answer

it is a bit unclear which is exactly problem you face since you don't provide any output or screenshot of what you don't like, but i ll explain the 2 most likely problems i see:

given your script is called ping.bat and looks like this:

 ping example.com

then the interpreter (cmd.exe) searches probes the paths in the environment variable %PATH% for something that looks like ping ... and it does that by appending each suffix from %PATHEXT% which contains something like .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. so, calling just ping from the ping.batleads to a search for ping.com ping.exe ping.bat and so on. the interpreter will find a ping.bat in the current working directory (your ping.bat) and calls it.

so, you will have a nice recursion here: ping.cmd executes the first line, searches for "ping", finds "ping.cmd", executes the first line, searches for "ping", finds "ping.cmd", executes the first line, searches for "ping", finds "ping.cmd" ...

the second problem you might have is this:

the interpreter of the batchfile will usually repeat the commands you have written to the .bat/.cmd file. thus something like this ping www.superuser.com will look like this:

 C:\Users\XYZ\Desktop>ping www.superuser.com

 Ping wird ausgeführt für superuser.com [64.34.119.12] mit 32 Bytes Daten:
 Antwort von 64.34.119.12: Bytes=32 Zeit=110ms TTL=46
 Antwort von 64.34.119.12: Bytes=32 Zeit=107ms TTL=46

if you want to get rid of C:\Users\XYZ\Desktop>ping www.superuser.com in the output of the script then you have to either prepend each line with an @ (eg, '@ping www.superuser.com') in the script or place a @echo off before the bunch of command lines you want to execute "quietly".

share|improve this answer

The local script execution seems to prevent ping.exe from running in a script. Try right-clicking, and "run as administrator". I'm looking up how to update the execution policy.

Just when I thought I knew something about Windows, they changed it.


Update: Recursion is the answer...

You can't call it ping.bat and call ping.exe

You also can't call it route.bat and call route.exe.

e.g, when I run ping.bat, then run it again as pingx.bat: enter image description here

share|improve this answer

Right click - Run As Administrator worked for me.

share|improve this answer
    
I could swear that this isn't correct and tested it - and he is right O_O –  nixda Aug 20 '13 at 16:42

I had the same issues. Here is the resolution:

Rename your ping.bat file to pingtest.bat

And ensure it contains:

ping xxx.xxx.xxx.001
ping xxx.xxx.xxx.002
ping xxx.xxx.xxx.003
pause

This will allow you to ping one or multiple addresses and will show the results on screen. This batch file can be run from anywhere on your PC by double clicking on it.

share|improve this answer

In other words Do not name your batch file (ping), use any other file name you want. and the following code will work perfectly.

@echo off

PING XXX.XXX.XXX.XXX

pause

share|improve this answer
    
That answer is the same as stefan and akira already gave. Only shorter –  nixda Mar 7 at 22:55

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.