I want to learn how to write batch scripts and tried to create a script which automatically runs this command in the command line once:
ping www.google.de -t
and displays the ping, so it would look like this:
Reply from XXX.XXX.X.XX: time=30ms
Reply from XXX.XXX.X.XX: time=31ms
Reply from XXX.XXX.X.XX: time=29ms
My problem is, that this will result in this when I execute this command as script:
My problem is that it will not execute the ping command at all, but just insert the command unlimited times in the console window as its shown in the screenshot.
I just created a new file, wrote ping www.google.de -t
in it, saved it as ping.bat
file and executed it with double clicking on it.
So how to write the batch file to start this command only once and display the ping result?
How can I execute ping command only for N number of packets and terminate the output automatically? Answer: Use ping option -c to specify the number of packets. After sending N number of packets, ping command will terminate automatically as explained below.
Enter in a command prompt window ping /?
and read the short help output after pressing RETURN. Or take a look on:
Explanation for option -t
given by Microsoft:
Specifies ping continue sending echo Request messages to the destination until interrupted. To interrupt and display statistics, press CTRL+ENTER. To interrupt and quit this command, press CTRL+C.
You may want to use:
@%SystemRoot%\system32\ping.exe -n 1 www.google.de
Or to check first if a server is available:
@echo off
set MyServer=Server.MyDomain.de
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer
echo %MyServer% is available.
rem Insert commands here, for example one or more net use to connect network drives.
goto :EOF
:NoServer
echo %MyServer% is not available yet.
pause
goto :EOF
I am sure you must have named the resultant bat file as "ping.bat". If you rename your file to something else say pingXXX.bat. It will definitely work. Try it out.
my batch file contains below code only
ping 172.31.29.1 -t
with file name as ping.bat
with file name abc.bat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With