I have a problem with tuning this code. The problem is the SET/P.
I have semplified the code and tested variuos method.
Can anyone expert comment/explain the result?
Code: Select all
@echo off
setlocal EnableDelayedExpansion
if not "%1"=="" goto :%1
echo HB 1 ^| find "TTL" ^| MAIN
"%~f0" HB 1 | find "TTL" | "%~f0" MAIN
echo(
echo HB 1 ^| findstr "TTL" ^| MAIN
"%~f0" HB 1 | findstr "TTL" | "%~f0" MAIN
echo(
echo HB 1 ^| find "TTL" ^| more ^| MAIN
"%~f0" HB 1 | find "TTL" | more | "%~f0" MAIN
pause
exit /b
:HB
for /L %%N in (0,1,5) do (
ping -n 2 127.0.0.1 >nul
start "HBPING" /B ping -n %2 127.0.0.1
)
exit /b
:MAIN
for /L %%n in (0,1,5) do (
set _HB=
set/p "_HB="
if defined _HB (
echo("!_HB!"
) else echo("N/D"
)
exit/b
results:
Code: Select all
HB 1 | find "TTL" | MAIN
"Risposta da 127.0.0.1: byte=32 durata<1m"
"s TTL=128"
"Risposta da 127.0.0.1: byte=32 durata<1m"
"s TTL=128"
"Risposta da 127.0.0.1: byte=32 durata<1m"
"s TTL=128"
HB 1 | findstr "TTL" | MAIN
"Risposta da 127.0.0.1: byte=32 durata<1ms TTL=128"
"N/D"
"N/D"
"N/D"
"N/D"
"N/D"
HB 1 | find "TTL" | more | MAIN
"Risposta da 127.0.0.1: byte=32 durata<1ms TTL=128"
"N/D"
"Risposta da 127.0.0.1: byte=32 durata<1ms TTL=128"
"N/D"
"Risposta da 127.0.0.1: byte=32 durata<1ms TTL=128"
"N/D"
Premere un tasto per continuare . . .
The best for me is the third.
It's possible eliminate the N/D cicle or the segmentation of the line?
Einstein1969