Solved How to display PING in a batch script without ending .bat

July 6, 2014 at 20:08:02
Specs: Windows 7
I am trying to write a menu script that will allow different network tests that I run frequently to show the results in the script. I would like this to be available to end-users to use before calling me.
I have the basic menu going, but every time i run PING, it completes and closed the script without showing the information the best I have been able to get so far is to redirect to a file to test that it works, but after, the .bat exits.

Please give ideas.

Here is what I have so far:
@ECHO OFF
TITLE Network Communication Test
Color F5
CD\
CLS

:MENU
CLS

ECHO ======== Check Communication ========
ECHO -------------------------------------
ECHO 1. PC1
ECHO 2. PC2
ECHO 3. PC3
ECHO 4. PC4
ECHO 5. PC5
ECHO -------------------------------------
ECHO 6. View ARP Table
ECHO 7. View IP Settings
ECHO -------------------------------------
ECHO 8. Not Yet Assigned
ECHO 9. Not Yet Assigned
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1

ECHO Test in Process...
REM ping.exe 192.168.2.101
start cmd.exe /c ping 192.168.2.101 > %temp%\PingTest.log
type %temp%\PingTest.log
ECHO +-----------------------------------+
ECHO |---------- TEST COMPLETE ----------|
ECHO +-----------------------------------+
ECHO.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE
GOTO MENU

:Selection2

REM Not yet coded

:Selection3

REM Not yet coded

:Selection4

REM Not yet coded

:Selection5

REM Not yet coded

:Selection6

REM Not yet coded

:Selection7

REM Not yet coded

:Selection8

REM Not yet coded

:Selection9

v

:Quit
CLS

ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE>NUL
EXIT


See More: How to display PING in a batch script without ending .bat

Report •

#1
July 6, 2014 at 21:05:13
try just using the ping command without creating a new cmd shell for it


(delete this ) -> start cmd.exe /c


Report •

#2
July 6, 2014 at 21:45:06
I concur with R3: you don't need all that overhead. From batch, several options depending, but simplest:
::=== begin batch snippet
set ip=192.168.9.99
ping -w 2000 -n 1 %ip%&&echo ping OK for %ip%||echo initial ping failed - two seconds, one try. Communication %ip% is not reliable as of: %date% %time%
::----
there is really no need to send output to file, unless you are logging. If you want logging, just insert the ping outputs, or your own messages, into the above and pipe out to file.

Report •

#3
July 7, 2014 at 00:31:28
✔ Best Answer
I put this together, might need some tweaking but will probably do what you're looking for:

@ECHO OFF
TITLE Network 
CLS

REM **** set the IPs for the PCs here ****

set usr1=

set pc2=192.168.1.2
set pc3=192.168.1.3
set pc4=192.168.1.4
set pc5=192.168.1.5

REM **** set the IPs for the PCs here ****

:MENU
@ECHO OFF
CLS

ECHO ======== Check Communication ========
ECHO -------------------------------------
ECHO 1. User selected address to Ping
ECHO 2. PC2
ECHO 3. PC3
ECHO 4. PC4
ECHO 5. PC5
ECHO -------------------------------------
ECHO 6. View ARP Table
ECHO 7. View Local IP Settings
ECHO 8. Flush DNS
ECHO 9. Net Shell
ECHO 10. View Active connections, open ports and applications PID
ECHO 11. Trace route
ECHO 12. Command Prompt 
ECHO 13. System Properties Panel
ECHO 14. Control Panel
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='10' GOTO Selection10
IF /I '%INPUT%'=='11' GOTO Selection11
IF /I '%INPUT%'=='12' GOTO Selection12
IF /I '%INPUT%'=='13' GOTO Selection13
IF /I '%INPUT%'=='14' GOTO Selection14
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-14] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1
(set /p usr1=Enter an IP or domain target to ping: %=%)
ping %usr1% > %temp%\PingTestusr1.log
start notepad %temp%\PingTestusr1.log
pause
call networkthing.bat


:Selection2
ECHO Pinging PC2
ping %pc2% > %temp%\PingTestPC2.log
start notepad %temp%\PingTestPC2.log
PAUSE
call networkthing.bat

:Selection3
ECHO Pinging PC3
ping %pc3% > %temp%\PingTestPC3.log
start notepad %temp%\PingTestPC3.log
PAUSE
call networkthing.bat

:Selection4
ECHO Pinging PC4
ping %pc4% > %temp%\PingTestPC4.log
start notepad %temp%\PingTestPC4.log
PAUSE
call networkthing.bat

:Selection5
ECHO Pinging PC5
ping %pc5% > %temp%\PingTest.log
start notepad %temp%\PingTest.log
PAUSE
call networkthing.bat

:Selection6
Echo Displaying ARP Table
arp -a > %temp%\arptable.log
start notepad.exe %temp%\arptable.log
PAUSE
call networkthing.bat

:Selection7
ECHO IPConfig [ Veiw all local setings ] 
ipconfig /all > %temp%\IPconfig.log
start notepad.exe %temp%\IPconfig.log
PAUSE
call networkthing.bat

:Selection8
ipconfig /flushdns
pause
call networkthing.bat

:Selection9
ECHO Opening Net Shell, type help at prompt for commands.
NetSh 

:Selection10
Echo "Active connections and open ports with PID"
netstat -ano > %temp%\netstatano.log
start notepad %temp%\netstatano.log
pause
call networkthing.bat

:Selection11
Echo Tracert starting....
set target1=
(set /p target1=Enter an IP or domain target to trace: %=%)
ECHO Begining trace to %target1%
@echo on
Tracert %target1% 
pause
@echo off
call networkthing.bat

:Selection12
cmd.exe /k 
pause 


:Selection13
Echo Opening System Properties panel.
sysdm.cpl
pause
call networkthing.bat

:Selection14
Echo Opening Control Panel
Control
pause
call networkthing.bat

:Quit
CLS

ECHO Press any key to kill window.
PAUSE>NUL
EXIT


Report •

Related Solutions

#4
July 11, 2014 at 16:24:30
Thank yo all for your input and help. I am still working on the script, but here is what I ended up using for my PING issue:

@ECHO OFF
TITLE Network Communication Test
Color 0A
CD\
CLS

:MENU
REM Clear variables
SET REGNUM=
CLS

ECHO ======== Check Communication ========
ECHO -------------------------------------
ECHO 1.  PC1
ECHO 2.  PC2
ECHO 3.  PC3
ECHO 4.  PC4
ECHO 5.  PC5
ECHO -------------------------------------
ECHO 6.  View ARP Table
ECHO 7.  View IP Settings
ECHO -------------------------------------
ECHO 8.  CODE TEST
ECHO 9.  Not Yet Assigned
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number: 

IF /I '%INPUT%'=='1' GOTO PING_REG
IF /I '%INPUT%'=='2' GOTO PING_REG
IF /I '%INPUT%'=='3' GOTO PING_REG
IF /I '%INPUT%'=='4' GOTO PING_REG
IF /I '%INPUT%'=='5' GOTO PING_REG
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:PING_REG

CLS
SET REGNUM=%INPUT%
ECHO Testing communication to Register %REGNUM%
ECHO Please wait...
PING -n 1 192.168.2.10%regnum% | FIND "Reply" > nul
IF errorlevel 1 GOTO :PING_FAIL
IF NOT errorlevel 1 SET REGNUM=1 && GOTO :PING_SUCCEED

:Selection6

REM Not yet coded
ECHO Displaying ARP Table
GOTO MENU

:Selection7

REM Not yet coded
ECHO IPConfig [ Veiw all local setings ]
GOTO MENU

:PING_SUCCEED

CLS
ECHO +========== TEST COMPLETE ==========+
ECHO +                                   +
ECHO +       REGISTER %REGNUM%is online        +
ECHO +                                   +
ECHO +===================================+
ECHO.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE>NUL
GOTO :MENU

:PING_FAIL

CLS
ECHO +========== TEST COMPLETE ==========+
ECHO +                                   +
ECHO +    Register %REGNUM% is not responding   +
ECHO + on the network. Please make sure  +
ECHO +   that it is powered on and the   +
ECHO +    Ethernet (Internet) cable is   +
ECHO +     connected to the LAN port.    +
ECHO +                                   +
ECHO +===================================+
ECHO.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE>NUL
GOTO :MENU

:Quit
CLS

ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE>NUL
EXIT


Report •

Ask Question