It is a bit unclear what is exactly the problem you face since you don't provide any output or screenshot of what you don't like, but I'll explain the two 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.bat
leads 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 batch file 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 @
(for example, '@ping www.superuser.com') in the script or place a @echo off
before the bunch of command lines you want to execute "quietly".
TL;DR;
Don't call your bat files the same as existing programs.
reading the fine manual would give you that answer. – l1zard – 2015-02-15T16:48:02.367
you may want to check your documentation on this. ping /help on windows or man ping on nix like systems. – l1zard – 2015-02-15T16:56:37.947
1Actually repeating or you see it pinging forever? Because that's what
-t
does. – ta.speot.is – 2011-06-18T03:52:45.097ping 127.0.0.1 -t <-- from cmd prompt, it does repeatedly. and that's not in a batch file (tested in win xp) – barlop – 2011-06-18T03:56:50.177
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 – 2011-06-18T03:58:18.113
"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 – 2011-06-18T04:00:39.577
I still haven't found a solution. I see the PING command being repeatedly called without any result. – pradeetp – 2011-06-19T17:04:28.593
Could you copy the output of your batch file ? And try « @ping -t 127.0.0.1 » – Nicolas – 2011-06-19T19:41:43.817
Did you try changing the name in the batch file to ping.exe? E.g. 'ping.exe -t XXX.XXX.XXX.XXX` which prevents the batch file from accidentally calling itself again. – Hennes – 2014-03-07T22:21:41.307