D
David Trimboli
I was writing a simple pinging interactive prompt to make pinging a lot
of machines more convenient. I wanted to include a shell escape with the
usual "!" command. One thing doesn't work: if I just type "!", I get an
error, ") was unexpected at this time." Why is this happening, and how
do I fix it? Do I need to escape something? (Windows XP SP3)
::::::::::Sample Output::::::::::
H:\>pinger
Pinger
Enter a host name to ping. "Exit" to exit.
Press any key to continue . . .
H:\>
::::::::::The Script:::::::::
@echo off
setlocal enableextensions enabledelayedexpansion
echo Pinger!
echo Enter a host name to ping. "Exit" to exit.
rompt
set /p "host=> "
if /i "%host%" equ "exit" goto :eof
if "%host:~0,1%" equ "!" goto shell
for /f "tokens=1-3* delims=: " %%i in ('ping -n 1 %host%') do (
if "%%i" equ "Pinging" set IP=%%k
if "!IP!" equ "with" set IP=%%j
if "%%i" equ "Reply" echo Reply from %%k
if "%%i" equ "Request" echo Request timed out. !IP!
if "%%j" equ "request" echo Host !host! not found.
)
goto prompt
:shell
if "%host:~0,1%" equ "%host%" (
cmd
) else (
%host:~1%
)
pause
goto rompt
of machines more convenient. I wanted to include a shell escape with the
usual "!" command. One thing doesn't work: if I just type "!", I get an
error, ") was unexpected at this time." Why is this happening, and how
do I fix it? Do I need to escape something? (Windows XP SP3)
::::::::::Sample Output::::::::::
H:\>pinger
Pinger
Enter a host name to ping. "Exit" to exit.
H:\stormcrow Reply from 143.48.3.46
!cd
Press any key to continue . . .
) was unexpected at this time.
H:\>
::::::::::The Script:::::::::
@echo off
setlocal enableextensions enabledelayedexpansion
echo Pinger!
echo Enter a host name to ping. "Exit" to exit.
rompt
set /p "host=> "
if /i "%host%" equ "exit" goto :eof
if "%host:~0,1%" equ "!" goto shell
for /f "tokens=1-3* delims=: " %%i in ('ping -n 1 %host%') do (
if "%%i" equ "Pinging" set IP=%%k
if "!IP!" equ "with" set IP=%%j
if "%%i" equ "Reply" echo Reply from %%k
if "%%i" equ "Request" echo Request timed out. !IP!
if "%%j" equ "request" echo Host !host! not found.
)
goto prompt
:shell
if "%host:~0,1%" equ "%host%" (
cmd
) else (
%host:~1%
)
pause
goto rompt