cmd - Read a string from a text file and copy it on another text file using batch file -


what want read text file containing ping results, detect string , copy in text file. strings want copy bold in example.

envoi d'une requˆte 'ping' sur star.c10r.facebook.com [31.13.81.17] avec 32 octets de donn‚esÿ: r‚ponse de 31.13.81.17ÿ: octets=32 temps=77 ms ttl=240

statistiques ping pour 31.13.81.17: paquetsÿ: envoy‚s = 1, re‡us = 1, perdus = 0 (perte 0%), dur‚e approximative des boucles en millisecondes : minimum = 77ms, maximum = 77ms, moyenne = 77ms

i tried execute program variable "resultat" does't appear in result.

@echo off setlocal enabledelayedexpansion  set output_file=result.txt >nul copy nul %output_file%  /f %%i in (testservers.txt) (   set server_address=address n/a   /f "tokens=1,2,3,4" %%a in ('ping -n 1 %%i ^&^& echo server_is_up') (        if %%a==r,ponse set resultat="%%b %%c %%d"         )     echo %%i [!server_address::=!] resultat >>%output_file% ) 

thank you.

thanks @matt's help, edit code:

@echo off setlocal enabledelayedexpansion  set output_file=result.txt  /f %%i in (testservers.txt) (   if not exist %output_file% type nul>%output_file%   /f "tokens=2 delims=:" %%a in ('ping -n 1 %%i ^| find "ttl="') (    if errorlevel 0  set resultat=up: %%a    )    echo %%i !resultat! >> %output_file%   set resultat=down ) 

i set default value of "resultat" down, because noticed change if "ttl" found, means server up. if not found program display default value of "resultat" down. section "octets=32 temps=77 ms ttl=240" displayed id server show stats. result this:

www.google.com up: octets=32 temps=470 ms ttl=42

www.facebook.com up: octets=32 temps=326 ms ttl=241
192.168.1.15 up: octets=32 temps<1ms ttl=128
10.21.107.90 down

thank help.

i see few problems here. you're not checking return of ping see if worked before server_is_up. you're not using server_address variable correctly , you're not calling resultant variable.

see if fixes it.

@echo off setlocal enabledelayedexpansion  set output_file=result.txt  /f %%i in (testservers.txt) (   if not exist %output_file% type nul>%output_file%   set server_address=address n/a   /f "tokens=2 delims=:" %%a in ('ping -n 1 %%i ^| find "ttl="') (    if errorlevel 0 echo %%1 && set resultat=%%a    if errorlevel 1 echo %%i down && set resultat=%%a down   )    echo %%i [!server_address!::=] !resultat! >>%output_file%   set resultat= 

)


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -