How to do simple PING batch file?

B

brett

I have this in a BAT file:

ping 192.168.2.1

ping yahoo.com

PAUSE

When I execute the file, I constantly see "ping 192.168.2.1" in the
command window. It keeps looping on that command. The PAUSE or PING
output never runs. All I want to do is ping the first address, display
the output then ping the second address and display the output. I'd
like the command window to stay open so I can see results from both
pings. Why doesn't the above work and how do I make it work?

Thanks,
Brett
 
S

Shenan Stanley

brett said:
I have this in a BAT file:

ping 192.168.2.1

ping yahoo.com

PAUSE

When I execute the file, I constantly see "ping 192.168.2.1" in the
command window. It keeps looping on that command. The PAUSE or
PING output never runs. All I want to do is ping the first
address, display the output then ping the second address and
display the output. I'd like the command window to stay open so I
can see results from both pings. Why doesn't the above work and
how do I make it work?


Open notepad.
paste this:

ping localhost
ping localhost
pause

Save the file as c:\test.cmd.
Close Notepad.
Open Windows Explorer.
Go to C:\ and find "test.cmd" and double-click on it.
What happens?
 
V

Vanguard

brett said:
I have this in a BAT file:

ping 192.168.2.1

ping yahoo.com

PAUSE

When I execute the file, I constantly see "ping 192.168.2.1" in the
command window. It keeps looping on that command. The PAUSE or PING
output never runs. All I want to do is ping the first address, display
the output then ping the second address and display the output. I'd
like the command window to stay open so I can see results from both
pings. Why doesn't the above work and how do I make it work?


Something else is in the .bat file that you are not telling us about, or
maybe you are using a ping program other than the one that comes in Windows.
I wrote the following .bat file:

ping 192.168.2.1
ping yahoo.com
pause

and got the following output:

C:\TEMP
ping 192.168.2.1

Pinging 192.168.2.1 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.2.1:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

C:\TEMP
ping yahoo.com

Pinging yahoo.com [66.94.234.13] with 32 bytes of data:

Reply from 66.94.234.13: bytes=32 time=111ms TTL=50
Reply from 66.94.234.13: bytes=32 time=93ms TTL=50
Reply from 66.94.234.13: bytes=32 time=91ms TTL=50
Reply from 66.94.234.13: bytes=32 time=93ms TTL=50

Ping statistics for 66.94.234.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 91ms, Maximum = 111ms, Average = 97ms

C:\TEMP
Press any key to continue . . .

I didn't see a problem with the commands you listed in the .bat file, and
they work okay for me. You didn't clearly explain what you meant by
"looping" on that [the first] ping command. Was the ping command
reexecuting, or were you getting repeated output from it? I got the
repeated timeout because there is no such host in my intranetwork with that
IP address. If I replace it with a valid IP address, the timeouts change to
the "Reply from" output (as was shown for the ping to yahoo.com).

Are you perchance running Microsoft's AntiSpyware program? If so, what
happens when you disable it?
 
P

Pegasus \(MVP\)

brett said:
I have this in a BAT file:

ping 192.168.2.1

ping yahoo.com

PAUSE

When I execute the file, I constantly see "ping 192.168.2.1" in the
command window. It keeps looping on that command. The PAUSE or PING
output never runs. All I want to do is ping the first address, display
the output then ping the second address and display the output. I'd
like the command window to stay open so I can see results from both
pings. Why doesn't the above work and how do I make it work?

Thanks,
Brett

Do not call your batch file "ping.bat" - call it something else!
 
B

brett

Renaming it to a CMD file but that didn't help. By looping, I mean the
command window just keep issuing the statements in the file over and
over. I never see any results. It is just constant new lines of the
ping statement flashing before the screen.

I'm not running the MS spyware software that I know of. I am running
ZoneAlarm and AVG but disabled both. That didn't change anything. Not
sure how they could be causing this behavior.

Thanks,
Brett
 
S

Shenan Stanley

brett said:
I have this in a BAT file:

ping 192.168.2.1

ping yahoo.com

PAUSE

When I execute the file, I constantly see "ping 192.168.2.1" in the
command window. It keeps looping on that command. The PAUSE or
PING output never runs. All I want to do is ping the first
address, display the output then ping the second address and
display the output. I'd like the command window to stay open so I
can see results from both pings. Why doesn't the above work and
how do I make it work?
Do not call your batch file "ping.bat" - call it something else!

*grin*
Good call. The resultant opening of command prompts at high speed would be
fun to watch, though.
 
S

Shenan Stanley

brett said:
Renaming it to a CMD file but that didn't help. By looping, I mean
the command window just keep issuing the statements in the file
over and over. I never see any results. It is just constant new
lines of the ping statement flashing before the screen.

I'm not running the MS spyware software that I know of. I am
running ZoneAlarm and AVG but disabled both. That didn't change
anything. Not sure how they could be causing this behavior.

Again..

Open notepad.
paste this:

ping localhost
ping localhost
pause

Save the file as c:\test.cmd.
Close Notepad.
Open Windows Explorer.
Go to C:\ and find "test.cmd" and double-click on it.
What happens?
 
B

brett

I see the problem. I ran your file off the root directory and it
worked fine. I then put it in a sub folder with the other bat file and
got the looping. The correct line is

c:\windows\system\ping.exe localhost

which works fine.

Brett
 
S

Shenan Stanley

brett said:
I see the problem. I ran your file off the root directory and it
worked fine. I then put it in a sub folder with the other bat file
and got the looping. The correct line is

c:\windows\system\ping.exe localhost

which works fine.

Actually...

%SystemRoot%\System32\ping.exe localhost

Would be more transferrable.
 
V

Vanguard

brett said:
I see the problem. I ran your file off the root directory and it
worked fine. I then put it in a sub folder with the other bat file and
got the looping. The correct line is

c:\windows\system\ping.exe localhost

which works fine.


So the problem really was as Pegasus mentioned where you used the same
filename as another program. Your "ping" command within the batch file was
calling that same batch file. I suspect you were running your batch file by
enter "ping" at the command line. Well, it doesn't matter if you used the
..bat or .cmd extension because you didn't specify it. If you had enter
"ping.exe" in the batch script then your batch file would not have
recursively called itself, or, as mentioned, specify the path to the file.
Personally I always add the extension to any program filename specified in a
batch script, but then I rarely name a batch file the same as an internal
command or an external program in the PATH.
 
S

Steve N.

brett said:
Renaming it to a CMD file but that didn't help.

No, do not use the name "ping" for it. It's just calling itself over and
over again instead of running ping.exe as you intended.

Steve N.
 
S

Steve N.

brett said:
I see the problem. I ran your file off the root directory and it
worked fine. I then put it in a sub folder with the other bat file and
got the looping. The correct line is

c:\windows\system\ping.exe localhost

which works fine.

Brett

As has aleady been mentioned, the problem exested because you named the
file ping.bat and ping.cmd while there exists ping.exe, which is what
the batch file is supposed to call. If you simply renamed your batch
file to something OTHER than ping.bat or ping.cmd then it will work no
matter where you locate it. Relocating it and specifying the path to
ping.exe are not addressing the real problem, that being the name of
your file.

Steve N
 

lol

Joined
Apr 3, 2017
Messages
1
Reaction score
0
"brett" <[email protected]> wrote in message
news:[email protected]...
> I have this in a BAT file:
>
> ping 192.168.2.1
>
> ping yahoo.com
>
> PAUSE
>
> When I execute the file, I constantly see "ping 192.168.2.1" in the
> command window. It keeps looping on that command. The PAUSE or PING
> output never runs. All I want to do is ping the first address, display
> the output then ping the second address and display the output. I'd
> like the command window to stay open so I can see results from both
> pings. Why doesn't the above work and how do I make it work?
>
> Thanks,
> Brett
>


Do not call your batch file "ping.bat" - call it something else!



Wow it was that easy? thank you so much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top