我制作此代码以在播放前检查ping,并且当较高的ping ping停止正确检测到更改时,当值从较低的2位数变化时发生。
如果有人能给我一个轻微的谢意。
@Echo Off
Title .Bat
Color 1f
FOR /F "tokens=6* delims==, " %%A in ('ping -n 2 br.leagueoflegends.com ^|find "="') do (Cls & Set MaiorPing=%%A & Set MenorPing=%%A & Set PingAtual=%%A)
:Pinges
FOR /F "tokens=6* delims==, " %%A in ('ping -n 2 br.leagueoflegends.com ^|find "="') do (Cls & Set PingAtual=%%A)
if /i %PingAtual% LEQ %Menorping% Set Menorping=%PingAtual%
if /i %PingAtual% GTR %Maiorping% Set Maiorping=%PingAtual%
Echo Current ping: %PingAtual%
Echo Lower ping: %Menorping%
Echo Higher ping: %Maiorping%
goto pinges
答案 0 :(得分:1)
我认为你的问题是比较。由于您未从数据中删除ms
后缀,因此GTR
和LEQ
操作数处理字符串而不是数字,因此,10ms
小于2ms
@echo off
setlocal enableextensions disabledelayedexpansion
title .Bat
color 1f
set "target=br.leagueoflegends.com"
set "lowPing=9999"
set "highPing=0"
:doPing
set "ping="
for /f "tokens=9" %%a in ('
ping -n 2 "%target%" ^|find "ms,"
') do for /f "delims=m " %%b in ("%%a") do set "ping=%%~b"
cls
if not defined ping (
echo No response
goto :doPing
)
if %ping% gtr %highPing% set "highPing=%ping%"
if %ping% lss %lowPing% set "lowPing=%ping%"
echo Current: %ping% Max: %highPing% Min: %lowPing%
goto :doPing
添加了一个aditional for
来将数字数据与单位分开。